Skip to content

Parser crasher on inline indexable types #2628

@N1ark

Description

@N1ark

Currently the parser crashes with the following stacktrace when declaring inline indexable types:

$ npx asc assembly/test.ts --target debug
node_modules/assemblyscript/std/portable/index.js:198
    throw new AssertionError(message);
          ^

AssertionError: assertion failed
    at null.Y.assert (node_modules/assemblyscript/std/portable/index.js:198:11)
    at $n.parseExpression (node_modules/assemblyscript/src/parser.ts:4320:18)
    at $n.parseExpressionStart (node_modules/assemblyscript/src/parser.ts:3863:25)
    at $n.parseExpression (node_modules/assemblyscript/src/parser.ts:4113:21)
    at $n.parseExpressionStatement (node_modules/assemblyscript/src/parser.ts:3095:21)
    at $n.parseStatement (node_modules/assemblyscript/src/parser.ts:2977:26)
    at $n.parseBlockStatement (node_modules/assemblyscript/src/parser.ts:3001:28)
    at $n.parseFunctionExpressionCommon (node_modules/assemblyscript/src/parser.ts:1639:21)
    at $n.parseFunctionExpression (node_modules/assemblyscript/src/parser.ts:1595:17)
    at $n.parseExpressionStart (node_modules/assemblyscript/src/parser.ts:3806:31)

Code that crashes the parser:

export const test = () => {
    const x: { [key in u8]: bool } = {};
    return x;
};

Code that doesn't crash the parser (throws an error):

export type Int8Map = { [key in u8]: bool };

export const test = () => {
    const x: Int8Map = {};
    return x;
};

Expected behaviour:
having an inline definition of the type should raise the same error as if it was declared separately

$ npx asc assembly/test.ts  --target debug
ERROR TS1110: Type expected.
    :
 1 │ export type Int8Map = { [key in u8]: bool };
   │                       ~
   └─ in assembly/test.ts(1)

FAILURE 1 parse error(s)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions