From 7877661f3525e5427db12717411959207927347a Mon Sep 17 00:00:00 2001 From: dcode Date: Wed, 30 Jan 2019 10:22:15 +0100 Subject: [PATCH] Emit an error when declaring a nullable basic type (for now) --- src/resolver.ts | 8 ++++++++ tests/compiler/basic-nullable.ts | 2 ++ tests/compiler/basic-nullable.untouched.wat | 0 3 files changed, 10 insertions(+) create mode 100644 tests/compiler/basic-nullable.ts create mode 100644 tests/compiler/basic-nullable.untouched.wat diff --git a/src/resolver.ts b/src/resolver.ts index 84a3fde3..33f5f883 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -196,6 +196,14 @@ export class Resolver extends DiagnosticEmitter { (type = typesLookup.get(localName)) || (type = typesLookup.get(globalName)) ) { + if (!type.is(TypeFlags.REFERENCE) && node.isNullable) { + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Basic_type_0_cannot_be_nullable, + node.range, type.toString() + ); + } + } return type; } } diff --git a/tests/compiler/basic-nullable.ts b/tests/compiler/basic-nullable.ts new file mode 100644 index 00000000..e3c9f36f --- /dev/null +++ b/tests/compiler/basic-nullable.ts @@ -0,0 +1,2 @@ +var a: i32 | null; +// Expect error: AS204 diff --git a/tests/compiler/basic-nullable.untouched.wat b/tests/compiler/basic-nullable.untouched.wat new file mode 100644 index 00000000..e69de29b