Skip to content

Commit 11e3c32

Browse files
committed
Error instead of crashing on reference typed fields
Since reference types can't be written to linear memory, they don't have proper byte sizes, which triggers an assert. Instead, the compiler should signal its lack of support for this feature. Fixes AssemblyScript#2726.
1 parent a6d26d7 commit 11e3c32

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/resolver.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,6 +3407,14 @@ export class Resolver extends DiagnosticEmitter {
34073407
if (boundInstance) {
34083408
let fieldType = boundInstance.type;
34093409
if (fieldType == Type.void) break; // failed to resolve earlier
3410+
if (fieldType.isExternalReference) {
3411+
this.error(
3412+
DiagnosticCode.Not_implemented_0,
3413+
assert(boundPrototype.typeNode).range,
3414+
"Reference typed fields"
3415+
);
3416+
break;
3417+
}
34103418
let needsLayout = true;
34113419
if (base) {
34123420
let existingMember = base.getMember(boundPrototype.name);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"stderr": [
3+
"Not implemented: Reference typed fields",
4+
"Not implemented: Reference typed fields",
5+
"EOF"
6+
]
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Foo {
2+
bar: externref = null;
3+
}
4+
5+
class Baz<T> {
6+
qux: T;
7+
}
8+
9+
new Foo();
10+
new Baz<externref>();
11+
12+
ERROR("EOF");

0 commit comments

Comments
 (0)