diff --git a/src/compiler.ts b/src/compiler.ts index baa324e97c..8105cdac29 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9035,10 +9035,29 @@ 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(); 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 new file mode 100644 index 0000000000..07404f851a --- /dev/null +++ b/tests/compiler/issues/2737.json @@ -0,0 +1,15 @@ +{ + "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;", + "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 new file mode 100644 index 0000000000..05d5faaae3 --- /dev/null +++ b/tests/compiler/issues/2737.ts @@ -0,0 +1,12 @@ +namespace foo { + export function bar(): void {} +} + +// Should error from missing type arguments: +foo.bar; +memory.data; + +// Should error from lacking first-class builtins: +atomic.fence; + +ERROR("EOF"); \ No newline at end of file