-
Notifications
You must be signed in to change notification settings - Fork 154
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
Function Calls are parsed as StructExpr #25
Comments
It should be the exact opposite way: struct Abc(u8);
let foo = Abc(0); should have |
Yep, bjorn3 is correct, the “tuple struct expression” is equivalent to parsing it as a function call to a constructor - I did not read the relevant reference page properly. As such, the tuple struct expression could be removed from the AST or could be designed to not be generated in normal parsing (and only exist after conversion from a method call after name resolution or something). However, there remains one problem related to this - if structs and functions have separate namespaces (i.e. you can define a struct and a function in the same scope with the same name and presumably no shadowing occurs), as suggested here, then how should this constructor vs function ambiguity be dealt with? I’m not sure how rustc does it, and I don’t know if there are more complicated rules to how the syntax should be parsed that we currently don’t know about. |
I guess its down to the arguments passed to the function call to help determine it in that case but it doesn't handle the case where arguments are the same for the struct and call maybe calls are just given preference over structs is about the only way i can think. |
struct Abc(u8);
fn Abc(_: u8) {}
fn main() {
Abc(0);
}
I think that reddit post was refering to something like struct Abc { a: u8 }
fn Abc(_: u8) {}
fn main() {
Abc(0);
} in which case the struct constructor is not in the value namespace, so there is no ambiguity. |
I just tried this with rustc:
and it gives:
So in this case the function is given preference |
That is because struct test {
x: i32
}
fn main() {
let x = test(1);
} is not allowed. Only tuple structs can be used with |
Good point my bad! |
@philberty I think that's because we haven't done the |
Yes please @NalaGinrut sorry my bad there on the naming. |
I think this was wrongly closed with the linking from commits |
this is fixed with #26 |
When there is a statement such as:
This is parsed as:
I am unsure if this is intentional of not but we can work around this if its intended.
The text was updated successfully, but these errors were encountered: