Skip to content

[Bug] Parser gets confused when parsing null | T #2455

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

Closed
dosisod opened this issue Aug 20, 2022 · 2 comments · Fixed by #2507
Closed

[Bug] Parser gets confused when parsing null | T #2455

dosisod opened this issue Aug 20, 2022 · 2 comments · Fixed by #2507
Labels

Comments

@dosisod
Copy link

dosisod commented Aug 20, 2022

Given the following AssemblyScript file:

class C {
  x: u8 | null;
  y: null | u8;
}

I get the following errors:

$ asc tmp.ts
ERROR TS1005: 'null' expected.
   :
 3 │ y: null | u8 = null;  // Error, TS1005: 'null' expected.
   │           ~~
   └─ in tmp.ts(3,13)

FAILURE 1 parse error(s)

I would expect both lines to work.

Compiling the following TypeScript code (note the added !'s) it works just fine:

class C {
  x!: number | null;
  y!: null | number;
}

It would seem that | null is only allowed at the end. The solution seems easy enough, seems to be somewhere near src/parser.ts (line 530ish) if I had to guess. I am not familiar with this codebase, but I wouldn't mind making a PR this if need be!

Possible related: #2300

@MaxGraey
Copy link
Member

MaxGraey commented Aug 20, 2022

This y: u8 | null = null doesn't support yet. Only references can be nullable for now.

@MaxGraey MaxGraey reopened this Aug 20, 2022
@MaxGraey
Copy link
Member

However, this definitely a parser issue:

class C {
  y: null | string;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants