-
-
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
Ambiguous identifier in pragma #23002
Comments
!nim c proc on(): void = discard
proc test() =
{.warning[ProveInit]:on.}
test() |
🐧 Linux bisect by @ringabout (member)devel 👎 FAILOutput
IRCompiled filesize0 bytes (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkProcDef.newTree(
newIdentNode("on"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkProcDef.newTree(
newIdentNode("test"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkPragma.newTree(
nnkExprColonExpr.newTree(
nnkBracketExpr.newTree(
newIdentNode("warning"),
newIdentNode("ProveInit")
),
newIdentNode("on")
)
)
)
),
nnkCall.newTree(
newIdentNode("test")
)
) stable 👎 FAILOutput
IRCompiled filesize0 bytes (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkProcDef.newTree(
newIdentNode("on"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkProcDef.newTree(
newIdentNode("test"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkPragma.newTree(
nnkExprColonExpr.newTree(
nnkBracketExpr.newTree(
newIdentNode("warning"),
newIdentNode("ProveInit")
),
newIdentNode("on")
)
)
)
),
nnkCall.newTree(
newIdentNode("test")
)
) 2.0.0 👎 FAILOutput
IRCompiled filesize0 bytes (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkProcDef.newTree(
newIdentNode("on"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkProcDef.newTree(
newIdentNode("test"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkPragma.newTree(
nnkExprColonExpr.newTree(
nnkBracketExpr.newTree(
newIdentNode("warning"),
newIdentNode("ProveInit")
),
newIdentNode("on")
)
)
)
),
nnkCall.newTree(
newIdentNode("test")
)
) 1.6.14 👎 FAILOutput
IRCompiled filesize0 bytes (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkProcDef.newTree(
newIdentNode("on"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkProcDef.newTree(
newIdentNode("test"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkPragma.newTree(
nnkExprColonExpr.newTree(
nnkBracketExpr.newTree(
newIdentNode("warning"),
newIdentNode("ProveInit")
),
newIdentNode("on")
)
)
)
),
nnkCall.newTree(
newIdentNode("test")
)
) 1.4.8 👎 FAILOutput
IRCompiled filesize0 bytes (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkProcDef.newTree(
newIdentNode("on"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkProcDef.newTree(
newIdentNode("test"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkPragma.newTree(
nnkExprColonExpr.newTree(
nnkBracketExpr.newTree(
newIdentNode("warning"),
newIdentNode("ProveInit")
),
newIdentNode("on")
)
)
)
),
nnkCall.newTree(
newIdentNode("test")
)
) 1.2.18 👎 FAILOutput
IRCompiled filesize0 bytes (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkProcDef.newTree(
newIdentNode("on"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkProcDef.newTree(
newIdentNode("test"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkPragma.newTree(
nnkExprColonExpr.newTree(
nnkBracketExpr.newTree(
newIdentNode("warning"),
newIdentNode("ProveInit")
),
newIdentNode("on")
)
)
)
),
nnkCall.newTree(
newIdentNode("test")
)
) 1.0.10 👎 FAILOutput
IRCompiled filesize0 bytes (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkProcDef.newTree(
newIdentNode("on"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkProcDef.newTree(
newIdentNode("test"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkPragma.newTree(
nnkExprColonExpr.newTree(
nnkBracketExpr.newTree(
newIdentNode("warning"),
newIdentNode("ProveInit")
),
newIdentNode("on")
)
)
)
),
nnkCall.newTree(
newIdentNode("test")
)
) Stats
🤖 Bug found in |
proc on = discard
const s: bool = on I image it to be similar with this case, viz, values are not be overloadable except enums etc. |
In #22841 I suggested special casing on/off for pragmas. We would not have a problem like this if we used true and false instead of on and off, because we know the expected type is a bool which is an enum containing true and false, but on and off are just random constants in system. There also wouldn't be a problem if on and off were defined as Instead of doing this though we can just interpret |
they're random constants with a type though and since the pragma expects "something with the bool type", it should reasonably be possible to narrow down the matching options. hardcoding seems like a loss - I'd rather see that "anything that evaluates to a bool" gets done, and then we can even have computed pragma values, ie full expressions. |
We would still be able to compute arbitrary expressions, The type inference logic is there for overloaded symbols (so unfortunately not const), but even with type inference the problem remains if the other module defines another |
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)
Description
testit2.nim:
testit.nim
inside the pragma, the evaluation should be looking for a
bool
, not aproc
- yet, the proc is matched (which in the real world example has more arguments)Nim Version
1.6.16, devel
Current Output
Expected Output
No response
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: