-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
directly parse on/off in pragmas, ignore user override #23097
Conversation
oof, this looks like quite the hack :/ |
This is what I thought would be the least disruptive (I think it makes some sense, it would also be documented). I think the cleanest thing to do would be The type narrowing from ambiguous identifiers as you suggested in #23002 (comment) would solve the given issues and seems reasonable in general, but I don't know if we should implement it just to encourage |
This should simply disambiguate an nkSymChoice to favor the variant that returns |
my feeling is that this one-off might be one of those things that stay with us for long and turns out to create subtle incomatibilities when / if this gets a proper fix - type-based disambiguation seems like a pretty natural feature though, could be used in many contexts (ie Also, I think this is fairly recent which might explain the sudden interest in the issue - I found it when bumping a project from 1.6.12 to 1.6.16. |
OK yeah the ambiguous identifier disambiguation is pretty easy, it just needs some annoying code shuffling.
Lines 3039 to 3047 in db9d800
which in turn directly receives a list of the ambiguous identifier candidates (which I didn't know) and just checks if there's more than 1: Lines 633 to 638 in db9d800
We just need to create a symchoice node from this list and plug it into |
Something I should have mentioned/realized is that this, even with the ambiguous identifier resolution: proc on() = discard
{.warning[ProveInit]: on.}
|
Then the disambiguation didn't do its job as there is a clear difference between |
Ok, sorry, it does work. My point was that the identifier isn't ambiguous but since it's a proc symbol it calls This, more expectedly, doesn't work: let on = 123
{.warning[ProveInit]: on.} Or |
should |
As found in #23124 which changes the type from I've finished preparing #23123 (the ambiguous identifier resolution suggested above) which fixes the issues, but later down the line if we want to protect against |
fixes #23002, fixes #22841, refs comments in #23097 When an identifier is ambiguous in scope (i.e. multiple imports contain symbols with the same name), attempt resolving it through type inference (by creating a symchoice). To do this efficiently, `qualifiedLookUp` had to be broken up so that `semExpr` can access the ambiguous candidates directly (now obtained directly via `lookUpCandidates`). This fixes the linked issues, but an example like: ```nim let on = 123 {.warning[ProveInit]: on.} ``` will still fail, since `on` is unambiguously the local `let` symbol here (this is also true for `proc on` but `proc` symbols generate symchoices anyway). Type symbols are not considered to not confuse the type inference. This includes the change in sigmatch, up to this point symchoices with nonoverloadable symbols could be created, they just wouldn't be considered during disambiguation. Now every proper symbol except types are considered in disambiguation, so the correct symbols must be picked during the creation of the symchoice node. I remember there being a violating case of this in the compiler, but this was very likely fixed by excluding type symbols as CI seems to have found no issues. The pure enum ambiguity test was disabled because ambiguous pure enums now behave like overloadable enums with this behavior, so we get a longer error message for `echo amb` like `type mismatch: got <MyEnum | OtherEnum> but expected T`
fixes #23002, fixes #22841, refs comments in #23097 When an identifier is ambiguous in scope (i.e. multiple imports contain symbols with the same name), attempt resolving it through type inference (by creating a symchoice). To do this efficiently, `qualifiedLookUp` had to be broken up so that `semExpr` can access the ambiguous candidates directly (now obtained directly via `lookUpCandidates`). This fixes the linked issues, but an example like: ```nim let on = 123 {.warning[ProveInit]: on.} ``` will still fail, since `on` is unambiguously the local `let` symbol here (this is also true for `proc on` but `proc` symbols generate symchoices anyway). Type symbols are not considered to not confuse the type inference. This includes the change in sigmatch, up to this point symchoices with nonoverloadable symbols could be created, they just wouldn't be considered during disambiguation. Now every proper symbol except types are considered in disambiguation, so the correct symbols must be picked during the creation of the symchoice node. I remember there being a violating case of this in the compiler, but this was very likely fixed by excluding type symbols as CI seems to have found no issues. The pure enum ambiguity test was disabled because ambiguous pure enums now behave like overloadable enums with this behavior, so we get a longer error message for `echo amb` like `type mismatch: got <MyEnum | OtherEnum> but expected T` (cherry picked from commit b280100)
fixes #23002, fixes #22841, refs comments in #23097 When an identifier is ambiguous in scope (i.e. multiple imports contain symbols with the same name), attempt resolving it through type inference (by creating a symchoice). To do this efficiently, `qualifiedLookUp` had to be broken up so that `semExpr` can access the ambiguous candidates directly (now obtained directly via `lookUpCandidates`). This fixes the linked issues, but an example like: ```nim let on = 123 {.warning[ProveInit]: on.} ``` will still fail, since `on` is unambiguously the local `let` symbol here (this is also true for `proc on` but `proc` symbols generate symchoices anyway). Type symbols are not considered to not confuse the type inference. This includes the change in sigmatch, up to this point symchoices with nonoverloadable symbols could be created, they just wouldn't be considered during disambiguation. Now every proper symbol except types are considered in disambiguation, so the correct symbols must be picked during the creation of the symchoice node. I remember there being a violating case of this in the compiler, but this was very likely fixed by excluding type symbols as CI seems to have found no issues. The pure enum ambiguity test was disabled because ambiguous pure enums now behave like overloadable enums with this behavior, so we get a longer error message for `echo amb` like `type mismatch: got <MyEnum | OtherEnum> but expected T` (cherry picked from commit b280100)
fixes #22841, fixes #23002
If a pragma like
{.checks: off.}
or{.warning[ProveInit]: on.}
has a direct identifier node on the RHS equal to eitheron
oroff
, directly parse them astrue
orfalse
, ignoring user overrides and overloads of the symbolson
andoff
.Something similar can be accomplished by turning
on
andoff
(which areconst on* = true
andconst off* = false
in system respectively) into:and coercing the RHS of pragmas to this type instead of
bool
(due to new enum type inference), however this would require all code that computes a custom value for the RHS like{.checks: foo().}
to change it to something like:Another problem is the symbols
on
andoff
enter into the enum symbol namespace which could cause ambiguity problems in normal code (although if someone has defined enum fieldson
andoff
, the pragmas like above wouldn't work anyway).Either change would require documentation, none is currently written in this PR because it's a POC of the initial proposal above. Will open RFC if required.