From 31e83c2eb2ed496bc9ccc840aaafae6c3c4e6859 Mon Sep 17 00:00:00 2001 From: dcode Date: Mon, 13 Sep 2021 00:00:55 +0200 Subject: [PATCH 1/2] Defuse assertion when mixing managed and unmanaged classes --- src/builtins.ts | 5 ++++- tests/compiler/unmanaged-errors.json | 8 ++++++++ tests/compiler/unmanaged-errors.ts | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/compiler/unmanaged-errors.json create mode 100644 tests/compiler/unmanaged-errors.ts diff --git a/src/builtins.ts b/src/builtins.ts index 79d7eb1d01..22228cfb22 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -9614,7 +9614,10 @@ function ensureVisitMembersOf(compiler: Compiler, instance: Class): void { ); // And make sure the base visitor function exists - if (base) ensureVisitMembersOf(compiler, base); + if (base && base.type.isManaged) { + // errored earlier if not managed + ensureVisitMembersOf(compiler, base); + } } /** Compiles the `__visit_members` function. */ diff --git a/tests/compiler/unmanaged-errors.json b/tests/compiler/unmanaged-errors.json new file mode 100644 index 0000000000..a9fb638d70 --- /dev/null +++ b/tests/compiler/unmanaged-errors.json @@ -0,0 +1,8 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "AS207: Unmanaged classes cannot extend managed classes", "Foo extends Base", + "EOF" + ] +} diff --git a/tests/compiler/unmanaged-errors.ts b/tests/compiler/unmanaged-errors.ts new file mode 100644 index 0000000000..9eca3d92be --- /dev/null +++ b/tests/compiler/unmanaged-errors.ts @@ -0,0 +1,9 @@ +// see: https://github.com/AssemblyScript/assemblyscript/issues/2067 + +@unmanaged export class Base {} +export class Baz {} +export class Foo extends Base { + constructor(public baz: Baz) { super(); } +} + +ERROR("EOF"); From f79aadf9bb57e9a8643e53a8e43057432c69dbe6 Mon Sep 17 00:00:00 2001 From: dcode Date: Mon, 13 Sep 2021 13:50:13 +0200 Subject: [PATCH 2/2] extend tests, use full message --- tests/compiler/unmanaged-errors.json | 3 ++- tests/compiler/unmanaged-errors.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/compiler/unmanaged-errors.json b/tests/compiler/unmanaged-errors.json index a9fb638d70..a636c438c9 100644 --- a/tests/compiler/unmanaged-errors.json +++ b/tests/compiler/unmanaged-errors.json @@ -2,7 +2,8 @@ "asc_flags": [ ], "stderr": [ - "AS207: Unmanaged classes cannot extend managed classes", "Foo extends Base", + "AS207: Unmanaged classes cannot extend managed classes and vice-versa.", "UnmanagedFoo extends ManagedBase", + "AS207: Unmanaged classes cannot extend managed classes and vice-versa.", "ManagedFoo extends UnmanagedBase", "EOF" ] } diff --git a/tests/compiler/unmanaged-errors.ts b/tests/compiler/unmanaged-errors.ts index 9eca3d92be..335ff73703 100644 --- a/tests/compiler/unmanaged-errors.ts +++ b/tests/compiler/unmanaged-errors.ts @@ -1,9 +1,12 @@ +export class ManagedBase {} +@unmanaged export class UnmanagedFoo extends ManagedBase {} // AS207 + // see: https://github.com/AssemblyScript/assemblyscript/issues/2067 -@unmanaged export class Base {} -export class Baz {} -export class Foo extends Base { - constructor(public baz: Baz) { super(); } +@unmanaged export class UnmanagedBase {} +export class ManagedBaz {} +export class ManagedFoo extends UnmanagedBase { // AS207 + constructor(public baz: ManagedBaz) { super(); } } ERROR("EOF");