Skip to content

Commit

Permalink
fix: Error on usage of reference types in fields (AssemblyScript#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
CountBleck committed Aug 13, 2023
1 parent 0ede7ff commit 321ed3d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3407,6 +3407,14 @@ export class Resolver extends DiagnosticEmitter {
if (boundInstance) {
let fieldType = boundInstance.type;
if (fieldType == Type.void) break; // failed to resolve earlier
if (fieldType.isExternalReference) {
this.error(
DiagnosticCode.Not_implemented_0,
assert(boundPrototype.typeNode).range,
"Reference typed fields"
);
break;
}
let needsLayout = true;
if (base) {
let existingMember = base.getMember(boundPrototype.name);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export class Type {
: signatureReference.toString(validWat);
} else {
return this.isNullableReference
? `${this.kindToString()}${nullablePostfix}}`
? `${this.kindToString()}${nullablePostfix}`
: this.kindToString();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/bindings/esm.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function instantiate(module, imports = {}) {
return Math.log(x);
},
"globalThis.globalThis": (
// bindings/esm/immutableGlobalNested: ref_extern | null}
// bindings/esm/immutableGlobalNested: ref_extern | null
globalThis.globalThis
),
"Date.getTimezoneOffset"() {
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/bindings/esm.release.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function instantiate(module, imports = {}) {
return Math.log(x);
},
"globalThis.globalThis": (
// bindings/esm/immutableGlobalNested: ref_extern | null}
// bindings/esm/immutableGlobalNested: ref_extern | null
globalThis.globalThis
),
"Date.getTimezoneOffset"() {
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/bindings/raw.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function instantiate(module, imports = {}) {
return Math.log(x);
},
"globalThis.globalThis": (
// bindings/esm/immutableGlobalNested: ref_extern | null}
// bindings/esm/immutableGlobalNested: ref_extern | null
globalThis.globalThis
),
"Date.getTimezoneOffset"() {
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/bindings/raw.release.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function instantiate(module, imports = {}) {
return Math.log(x);
},
"globalThis.globalThis": (
// bindings/esm/immutableGlobalNested: ref_extern | null}
// bindings/esm/immutableGlobalNested: ref_extern | null
globalThis.globalThis
),
"Date.getTimezoneOffset"() {
Expand Down
8 changes: 4 additions & 4 deletions tests/compiler/features/reference-types.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(export "nonNullReal" (global $features/reference-types/nonNullReal))
(export "memory" (memory $0))
(start $~start)
(func $features/reference-types/testLocal<ref_func|null}>
(func $features/reference-types/testLocal<ref_func|null>
(local $local funcref)
ref.null nofunc
local.set $local
Expand Down Expand Up @@ -68,7 +68,7 @@
unreachable
end
)
(func $features/reference-types/testLocal<ref_extern|null}>
(func $features/reference-types/testLocal<ref_extern|null>
(local $local externref)
ref.null noextern
local.set $local
Expand Down Expand Up @@ -256,8 +256,8 @@
call $~lib/builtins/abort
unreachable
end
call $features/reference-types/testLocal<ref_func|null}>
call $features/reference-types/testLocal<ref_extern|null}>
call $features/reference-types/testLocal<ref_func|null>
call $features/reference-types/testLocal<ref_extern|null>
ref.func $features/reference-types/someFunc
global.set $features/reference-types/funcGlobal
global.get $features/reference-types/funcGlobal
Expand Down
7 changes: 7 additions & 0 deletions tests/compiler/field-reference-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"stderr": [
"Not implemented: Reference typed fields",
"Not implemented: Reference typed fields",
"EOF"
]
}
12 changes: 12 additions & 0 deletions tests/compiler/field-reference-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Foo {
bar: externref = null;
}

class Baz<T> {
qux: T;
}

new Foo();
new Baz<externref>();

ERROR("EOF");

0 comments on commit 321ed3d

Please sign in to comment.