Skip to content

Commit 321ed3d

Browse files
authoredAug 13, 2023
fix: Error on usage of reference types in fields (#2733)
1 parent 0ede7ff commit 321ed3d

9 files changed

+36
-9
lines changed
 

‎src/resolver.ts

+8
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);

‎src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ export class Type {
638638
: signatureReference.toString(validWat);
639639
} else {
640640
return this.isNullableReference
641-
? `${this.kindToString()}${nullablePostfix}}`
641+
? `${this.kindToString()}${nullablePostfix}`
642642
: this.kindToString();
643643
}
644644
}

‎tests/compiler/bindings/esm.debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function instantiate(module, imports = {}) {
2323
return Math.log(x);
2424
},
2525
"globalThis.globalThis": (
26-
// bindings/esm/immutableGlobalNested: ref_extern | null}
26+
// bindings/esm/immutableGlobalNested: ref_extern | null
2727
globalThis.globalThis
2828
),
2929
"Date.getTimezoneOffset"() {

‎tests/compiler/bindings/esm.release.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function instantiate(module, imports = {}) {
2323
return Math.log(x);
2424
},
2525
"globalThis.globalThis": (
26-
// bindings/esm/immutableGlobalNested: ref_extern | null}
26+
// bindings/esm/immutableGlobalNested: ref_extern | null
2727
globalThis.globalThis
2828
),
2929
"Date.getTimezoneOffset"() {

‎tests/compiler/bindings/raw.debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function instantiate(module, imports = {}) {
2323
return Math.log(x);
2424
},
2525
"globalThis.globalThis": (
26-
// bindings/esm/immutableGlobalNested: ref_extern | null}
26+
// bindings/esm/immutableGlobalNested: ref_extern | null
2727
globalThis.globalThis
2828
),
2929
"Date.getTimezoneOffset"() {

‎tests/compiler/bindings/raw.release.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function instantiate(module, imports = {}) {
2323
return Math.log(x);
2424
},
2525
"globalThis.globalThis": (
26-
// bindings/esm/immutableGlobalNested: ref_extern | null}
26+
// bindings/esm/immutableGlobalNested: ref_extern | null
2727
globalThis.globalThis
2828
),
2929
"Date.getTimezoneOffset"() {

‎tests/compiler/features/reference-types.debug.wat

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
(export "nonNullReal" (global $features/reference-types/nonNullReal))
3636
(export "memory" (memory $0))
3737
(start $~start)
38-
(func $features/reference-types/testLocal<ref_func|null}>
38+
(func $features/reference-types/testLocal<ref_func|null>
3939
(local $local funcref)
4040
ref.null nofunc
4141
local.set $local
@@ -68,7 +68,7 @@
6868
unreachable
6969
end
7070
)
71-
(func $features/reference-types/testLocal<ref_extern|null}>
71+
(func $features/reference-types/testLocal<ref_extern|null>
7272
(local $local externref)
7373
ref.null noextern
7474
local.set $local
@@ -256,8 +256,8 @@
256256
call $~lib/builtins/abort
257257
unreachable
258258
end
259-
call $features/reference-types/testLocal<ref_func|null}>
260-
call $features/reference-types/testLocal<ref_extern|null}>
259+
call $features/reference-types/testLocal<ref_func|null>
260+
call $features/reference-types/testLocal<ref_extern|null>
261261
ref.func $features/reference-types/someFunc
262262
global.set $features/reference-types/funcGlobal
263263
global.get $features/reference-types/funcGlobal
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+
}
+12
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)
Please sign in to comment.