-
-
Notifications
You must be signed in to change notification settings - Fork 815
Warn if a top-level definition shadows an imported one #4545
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
base: main
Are you sure you want to change the base?
Conversation
The latter is intended behaviour. Types and values live in different namespaces |
e3a3e62
to
ace5809
Compare
I see. I have updated the warning message and changelog. |
03f077c
to
c92f383
Compare
I also updated the test result of this existing test: #[test]
fn used_shadowed_imported_value() {
assert_warning!(
(
"thepackage",
"wibble",
"
pub const wibble = 1
"
),
"
import wibble.{wibble}
pub const wibble = wibble
"
);
} Since redefining values is not actually legal, there should be a warning on shadowing of |
That one should not warn 🙏 Until #614 is resolved it has valid uses. |
e4233e4
to
e63b49a
Compare
Thanks for your clarification! I've added logic to not complain about direct re-exports like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I've actually realised I was wrong with my previous guidance, the programmer should in that case use the qualified syntax. Sorry, I was quite tired when I wrote it! Could you remove that exception please 🙏
compiler-core/src/analyse.rs
Outdated
location: f.location, | ||
name, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the code for this check into the existing definition analysis rather than iterating over the functions and constants again 🙏
8d8f6c7
to
d32bb06
Compare
Of course! 💜 |
This PR hopefully resolves #4519. A new warning will be shown like this:
However, I found a similar issue for constructors and type aliases. Especially if we import a constructor and define a type (not constructor) with the same name, the imported item will be used:
Is this an intended behavior? If not I think we should add an error for this.