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 error, i think #2780

Open
lortonx opened this issue Nov 5, 2023 · 8 comments
Open

Parser error, i think #2780

lortonx opened this issue Nov 5, 2023 · 8 comments
Labels

Comments

@lortonx
Copy link

lortonx commented Nov 5, 2023

Bug description

I understand that I am doing the wrong things in the assembly script, but it seems to me that this error should not look like what is shown below. Hope this helps improve Assemblyscript.
image

Steps to reproduce

run

let tries = 64;
const aliof = alignof<typeof tries>();
// or
const siof = sizeof<typeof tries>();

AssemblyScript version

v0.27.15

@lortonx lortonx added the bug label Nov 5, 2023
@CountBleck
Copy link
Member

I'm not sure if AS supports typeof yet.

@HerrCai0907
Copy link
Member

I'm not sure if AS supports typeof yet.

yes. typeof will return a string of object type

@HerrCai0907 HerrCai0907 self-assigned this Nov 6, 2023
@lortonx
Copy link
Author

lortonx commented Nov 6, 2023

I'm not sure if AS supports typeof yet.

The problem is not even that, the problem is an error in the parser. Unfortunately, I didn’t check the typeof, but I saw that this have checks in tests https://github.com/AssemblyScript/assemblyscript/blob/main/tests/compiler/typeof.ts

@HerrCai0907
Copy link
Member

HerrCai0907 commented Nov 6, 2023

I have token a look about this issue. It is because parser handle alignof< typeof 1 > (); as Identifier LessThan Expression GreaterThan NotFinishedFunctionExpression.
It is hard to distinguish generic and lessThan and greaterThan operator without semantic analysis. But unfortunately, we will not do any semantic analysis in parser stage.

@CountBleck
Copy link
Member

typeof x when used as a type is parsed separately and differently from typeof x when used as an expression. For instance, typeof x(), typeof (x), typeof x[a ? b : c], and so on are parser errors in TS.

I suspect that typeof for types hasn't been implemented yet.

@CountBleck
Copy link
Member

CountBleck commented Nov 6, 2023

The error you reported indicates the parser expected code like this, which is seen as (y < typeof x) > ((): i32 => 0), without the extra parentheses.

Edit: @HerrCai0907 beat me to it by 6 minutes and I didn't notice.

@HerrCai0907
Copy link
Member

HerrCai0907 commented Nov 6, 2023

Interesting thing is TS also have similar problem.
true<false>(true); is valid but let a=true;a<false>(true); is invalid.

@CountBleck
Copy link
Member

It is hard to distinguish generic and lessThan and greaterThan operator without semantic analysis.

Semantic analysis isn't necessary. TypeScript eagerly parses generics (which makes sense; practically no one would write a < typeof b, let alone a < typeof b > () => ... or a < typeof b > (c))

Interesting thing is TS also have similar problem.

You actually brought up what I typed above as I was typing it. 😆
Calling it a problem is a bit of an exaggeration, and true is probably treated specially as a keyword, thereby causing that case to be valid. It's not a major issue, since true < false > (true) is a generally useless expression.

HerrCai0907 added a commit to HerrCai0907/assemblyscript that referenced this issue Nov 6, 2023
HerrCai0907 added a commit to HerrCai0907/assemblyscript that referenced this issue Nov 6, 2023
@HerrCai0907 HerrCai0907 removed their assignment Jan 11, 2024
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.

3 participants