Repository: AssemblyScript/assemblyscript

Issue #1859: compiler crash: class with externref field 
Created: 2021-05-19T17:47:01Z
code to reproduce:
// @ts-ignore
@external("http", "_request_get")
declare function _http_request_get(s: string): externref;


class Builder {
    inner: externref;

    private constructor(inner: externref) {
        this.inner = inner;
    }

    static get(url: string): Builder {
        const inner = _http_request_get(url);

        return new Builder(inner);
    }
}


export function invoke(): void {
    let builder = Builder.get("ya.ru");
}
compiler version: "assemblyscript": "^0.18.31"
npm version: 7.5.3
stacktrace
▌ Whoops, the AssemblyScript compiler has crashed during compile :-(
▌ 
▌ Here is a stack trace that may or may not be useful:
▌ 
▌ AssertionError: assertion failed
▌     at assert (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/std/portable/index.js:199:9)
▌     at h.finishResolveClass (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/resolver.ts:3101:13)
▌     at h.resolveClass (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/resolver.ts:2970:10)
▌     at h.resolveClassInclTypeArguments (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/resolver.ts:3316:17)
▌     at h.resolveNamedType (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/resolver.ts:252:29)
▌     at h.resolveType (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/resolver.ts:154:21)
▌     at h.resolveFunction (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/resolver.ts:2749:23)
▌     at h.maybeInferCall (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/resolver.ts:808:17)
▌     at f.compileCallExpression (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/compiler.ts:6243:46)
▌     at f.compileExpression (<cut>/wasm/rt_test/node_modules/assemblyscript/dist/webpack:/assemblyscript/src/compiler.ts:3435:21)

Duplicate issue #2314: Support anyref as a field type of a class
Created: 2022-06-09T07:36:46Z
Code:
class EntityProxy {
    private refEntity: anyref;
      constructor(refEntity: anyref) {
        this.refEntity = refEntity;
    }
}
export const proxy = new EntityProxy(null);

Output:
Whoops, the AssemblyScript compiler has crashed during compile :-(

Here is the stack trace hinting at the problem, perhaps it's useful?
/Users/bruce/Projects/libs/node_modules/assemblyscript/std/portable/index.js:200
     throw new AssertionError(message);
     
AssertionError: assertion failed
     at q.assert (/Users/bruce/Projects/libs/node_modules/assemblyscript/std/portable/index.js:200:11)
     at Zn.finishResolveClass (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/resolver.ts:3205:13)
     at Zn.resolveClass (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/resolver.ts:2999:10)
     at Zn.resolveClassInclTypeArguments (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/resolver.ts:3428:17)
     at oi.compileNewExpression (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/compiler.ts:8787:37)
     at oi.compileExpression (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/compiler.ts:3449:21)
     at oi.compileGlobal (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/compiler.ts:1082:25)
     at oi.compileTopLevelStatement (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/compiler.ts:2062:20)
     at oi.compileFile (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/compiler.ts:1013:12)
     at oi.compile (/Users/bruce/Projects/libs/node_modules/assemblyscript/src/compiler.ts:497:14)

Is it possible to support anyref as a field type of a class?

Closing comment (2022-06-11T18:03:26Z): Duplicate of #1859