Skip to content
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

Parser crasher on inline indexable types #2628

Closed
N1ark opened this issue Jan 22, 2023 · 2 comments
Closed

Parser crasher on inline indexable types #2628

N1ark opened this issue Jan 22, 2023 · 2 comments

Comments

@N1ark
Copy link

N1ark commented Jan 22, 2023

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)
@dcodeIO
Copy link
Member

dcodeIO commented Jan 22, 2023

The assertion has been addressed in #2629. Complex types like these cannot currently be parsed, as there isn't really an implementation story for these yet. It would of course be preferable if the parser at least skipped them to then diagnose what exactly is not supported.

@dcodeIO dcodeIO added compatibility and removed bug labels Jan 22, 2023
@N1ark
Copy link
Author

N1ark commented Jan 23, 2023

Good to know - thanks ! Closing the issue

@N1ark N1ark closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants