You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When lowering calls, we are not handling callable items that share names with identifiers. For example, struct methods called the same as one of their fields get treated as identifiers, thus lowering fails.
To me, this looks like an IR issue, but following the Language Guide, this may well be expected. If this is intentional, we should improve the error diagnostic to mention these name collisions (which can be confusing).
Example (playground example below):
struct A {
field: u32,
}
impl A {
fn field(self: &A) -> u32 {
self.field
}
}
fn main() {
let a = A { field: 42 };
println!("a.field={}", a.field());
}
Output:
error: function or static expected
--> [program.alu:13:28](https://play.alumina-lang.net/#)
Fields have precedence over methods in name resolution, so from the behavior perspective, this is expected, but I agree that it deserves a better error message.
bqwstt
changed the title
diag/ir: methods sharing names with struct fields produce unexpected results/messages
diag: methods sharing names with struct fields produce confusing diagnostic message
Oct 13, 2024
Unsure if this is a diagnostic or IR issue.
When lowering calls, we are not handling callable items that share names with identifiers. For example, struct methods called the same as one of their fields get treated as identifiers, thus lowering fails.
To me, this looks like an IR issue, but following the Language Guide, this may well be expected. If this is intentional, we should improve the error diagnostic to mention these name collisions (which can be confusing).
Example (playground example below):
Output:
This happens in
ir/mono/mod.rs
'slower_call
:alumina/src/alumina-boot/src/ir/mono/mod.rs
Lines 5067 to 5093 in 304bf3f
Reproducible Example
https://play.alumina-lang.net/?code=1695451deb28b0f0
The above is a rather silly example (could just use
field
directly), but similar situations may happen (e.g., with a builder struct).Compilation Info
Revision:
304bf3f4ff1f77739f31f3f7fe8c88c0f5b9e9fb
The text was updated successfully, but these errors were encountered: