From 6eea3dc57ad5357fbd5339117f6a9c0e80b649e5 Mon Sep 17 00:00:00 2001 From: CountBleck Date: Sat, 9 Sep 2023 15:26:29 -0700 Subject: [PATCH 1/2] Ensure call-less member expressions referencing generic functions error The equivalent check exists for identifiers, so I ripped that same code and inserted it in compilePropertyAccessExpression. While this is technically a fix for #2737, we're not quite done yet. --- src/compiler.ts | 10 ++++++++++ tests/compiler/issues/2737.json | 13 +++++++++++++ tests/compiler/issues/2737.ts | 9 +++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/compiler/issues/2737.json create mode 100644 tests/compiler/issues/2737.ts diff --git a/src/compiler.ts b/src/compiler.ts index baa324e97c..55d1199c53 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9035,6 +9035,16 @@ export class Compiler extends DiagnosticEmitter { } case ElementKind.FunctionPrototype: { let functionPrototype = target; + let typeParameterNodes = functionPrototype.typeParameterNodes; + + if (typeParameterNodes && typeParameterNodes.length != 0) { + this.error( + DiagnosticCode.Type_argument_expected, + expression.range + ); + break; // also diagnose 'not a value at runtime' + } + let functionInstance = this.resolver.resolveFunction(functionPrototype, null); if (!functionInstance) return module.unreachable(); if (!this.compileFunction(functionInstance)) return module.unreachable(); diff --git a/tests/compiler/issues/2737.json b/tests/compiler/issues/2737.json new file mode 100644 index 0000000000..28dd0d8e53 --- /dev/null +++ b/tests/compiler/issues/2737.json @@ -0,0 +1,13 @@ +{ + "stderr": [ + "TS1140: Type argument expected.", + "foo.bar;", + "AS234: Expression does not compile to a value at runtime.", + "foo.bar;", + "TS1140: Type argument expected.", + "memory.data;", + "AS234: Expression does not compile to a value at runtime.", + "memory.data;", + "EOF" + ] +} \ No newline at end of file diff --git a/tests/compiler/issues/2737.ts b/tests/compiler/issues/2737.ts new file mode 100644 index 0000000000..b7981bafc9 --- /dev/null +++ b/tests/compiler/issues/2737.ts @@ -0,0 +1,9 @@ +namespace foo { + export function bar(): void {} +} + +// Should error from missing type arguments: +foo.bar; +memory.data; + +ERROR("EOF"); \ No newline at end of file From dbdced06617e5c1870e362d57b9fe0c1bc197a2c Mon Sep 17 00:00:00 2001 From: CountBleck Date: Sat, 9 Sep 2023 15:33:09 -0700 Subject: [PATCH 2/2] Ensure call-less member expressions referencing builtin functions error This commit uses the same approach from the previous one: yoinking code from compileIdentifierExpression. This actually has no influence on the example in #2737, but I can say this commit truly fixes #2737 in spirit. --- src/compiler.ts | 9 +++++++++ tests/compiler/issues/2737.json | 2 ++ tests/compiler/issues/2737.ts | 3 +++ 3 files changed, 14 insertions(+) diff --git a/src/compiler.ts b/src/compiler.ts index 55d1199c53..8105cdac29 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9049,6 +9049,15 @@ export class Compiler extends DiagnosticEmitter { if (!functionInstance) return module.unreachable(); if (!this.compileFunction(functionInstance)) return module.unreachable(); this.currentType = functionInstance.type; + + if (functionInstance.hasDecorator(DecoratorFlags.Builtin)) { + this.error( + DiagnosticCode.Not_implemented_0, + expression.range, "First-class built-ins" + ); + return module.unreachable(); + } + let offset = this.ensureRuntimeFunction(functionInstance); return this.options.isWasm64 ? module.i64(i64_low(offset), i64_high(offset)) diff --git a/tests/compiler/issues/2737.json b/tests/compiler/issues/2737.json index 28dd0d8e53..07404f851a 100644 --- a/tests/compiler/issues/2737.json +++ b/tests/compiler/issues/2737.json @@ -8,6 +8,8 @@ "memory.data;", "AS234: Expression does not compile to a value at runtime.", "memory.data;", + "AS100: Not implemented: First-class built-ins", + "atomic.fence;", "EOF" ] } \ No newline at end of file diff --git a/tests/compiler/issues/2737.ts b/tests/compiler/issues/2737.ts index b7981bafc9..05d5faaae3 100644 --- a/tests/compiler/issues/2737.ts +++ b/tests/compiler/issues/2737.ts @@ -6,4 +6,7 @@ namespace foo { foo.bar; memory.data; +// Should error from lacking first-class builtins: +atomic.fence; + ERROR("EOF"); \ No newline at end of file