Skip to content

Error on usage of reference types in fields #2733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");