Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 58ed2b2

Browse files
fix: Ensure call-less references to builtin functions in namespaces error (#2738)
1 parent 73193f0 commit 58ed2b2

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

‎src/compiler.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9044,10 +9044,29 @@ export class Compiler extends DiagnosticEmitter {
90449044
}
90459045
case ElementKind.FunctionPrototype: {
90469046
let functionPrototype = <FunctionPrototype>target;
9047+
let typeParameterNodes = functionPrototype.typeParameterNodes;
9048+
9049+
if (typeParameterNodes && typeParameterNodes.length != 0) {
9050+
this.error(
9051+
DiagnosticCode.Type_argument_expected,
9052+
expression.range
9053+
);
9054+
break; // also diagnose 'not a value at runtime'
9055+
}
9056+
90479057
let functionInstance = this.resolver.resolveFunction(functionPrototype, null);
90489058
if (!functionInstance) return module.unreachable();
90499059
if (!this.compileFunction(functionInstance)) return module.unreachable();
90509060
this.currentType = functionInstance.type;
9061+
9062+
if (functionInstance.hasDecorator(DecoratorFlags.Builtin)) {
9063+
this.error(
9064+
DiagnosticCode.Not_implemented_0,
9065+
expression.range, "First-class built-ins"
9066+
);
9067+
return module.unreachable();
9068+
}
9069+
90519070
let offset = this.ensureRuntimeFunction(functionInstance);
90529071
return this.options.isWasm64
90539072
? module.i64(i64_low(offset), i64_high(offset))

‎tests/compiler/issues/2737.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"stderr": [
3+
"TS1140: Type argument expected.",
4+
"foo.bar;",
5+
"AS234: Expression does not compile to a value at runtime.",
6+
"foo.bar;",
7+
"TS1140: Type argument expected.",
8+
"memory.data;",
9+
"AS234: Expression does not compile to a value at runtime.",
10+
"memory.data;",
11+
"AS100: Not implemented: First-class built-ins",
12+
"atomic.fence;",
13+
"EOF"
14+
]
15+
}

‎tests/compiler/issues/2737.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace foo {
2+
export function bar<T>(): void {}
3+
}
4+
5+
// Should error from missing type arguments:
6+
foo.bar;
7+
memory.data;
8+
9+
// Should error from lacking first-class builtins:
10+
atomic.fence;
11+
12+
ERROR("EOF");

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /