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

Missing error when struct.new has too many arguments in assembler #6739

Open
hgruniaux opened this issue Jul 12, 2024 · 2 comments
Open

Missing error when struct.new has too many arguments in assembler #6739

hgruniaux opened this issue Jul 12, 2024 · 2 comments

Comments

@hgruniaux
Copy link

hgruniaux commented Jul 12, 2024

When assembling the following invalid WAT code:

(module
    (type $t (struct))
    (func (param i32)
        (struct.new $t (local.get 0))))

the assembler rejects it with the following error message:

unexpected false: non-final block elements returning a value must be drop()ed
unexpected true: if block is not returning a value, final element should not flow out a value

I think, it will be better that it generates an error about the fact that struct.new has too many arguments.

@kripken
Copy link
Member

kripken commented Jul 12, 2024

Unfortunately the wat text format considers code like this equal:

(struct.new $t (local.get 0))

(local.get 0)
(struct.new $t)

So the parser has to accept it.

Though if an error happens later, as in this testcase, then we could perhaps look back at the wat to see if we can print a better error message. But connecting the validator to the wat text that was already fully processed at that point might not be easy. @tlively what do you think?

@tlively
Copy link
Member

tlively commented Jul 14, 2024

In particular, when the parser parses the struct.new $t, as far as it knows, that local.get 0 could be consumed by a later instruction. Even if we did more error checking in the parser, it wouldn't be clear that an error occurred until the end of the block, but then it would be unclear which instruction was intended to consume it, so we still couldn't print a useful error message. In principle, we could use the parentheses to inform heuristics to improve the error message, but that would break a very important abstraction boundary in the implementation and make the code too complicated.

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

No branches or pull requests

3 participants