-
-
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
Overload resultion with generic variables an inheritance #23870
Conversation
just to add some context here, the inheritance penalty is not looked at unless other more important factors are considered. (exact matches etc). For this reason a "penalty" of zero doesn't mean "no penalty" as in "better then a penalty of 1,2,..etc", it means "no relation". No relation has to be worse then any inheritance penalty because at least there is a relation if the penalty is non-zero. |
actually, I think it would make more sense to rework this to make a penalty of 0 actually mean what it conceptually should and make the default -1 with negatives signifying "no inheritance relation". |
29cb491
to
37ea900
Compare
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
The test case diff is self explanatory (cherry picked from commit c1f91c2)
The test case diff is self explanatory (cherry picked from commit c1f91c2)
This broke something with varargs in a way I can't reproduce. It's the cause of this: nim-works/cps#333 Trying to compile # a.nim
import std/macros
type NormNode* = distinct NimNode
converter normNodeToNimNode(n: NormNode): NimNode =
n.NimNode
# b.nim
import std/macros
from std/typetraits import distinctBase
from a import NormNode
proc upgradeToNormalizedNode*[T](n: T): NormNode =
when T is NormNode:
n
elif T is NimNode or T is distinct and distinctBase(T) is NimNode:
NormNode n
else:
{.error: "abc".}
type
AnyNodeVarargs = varargs[NormNode, upgradeToNormalizedNode]
proc newTree*(kind: NimNodeKind, n: AnyNodeVarargs): NormNode =
NormNode macros.newTree(kind, varargs[NimNode] n)
proc wrap*(kind: NimNodeKind, n: NormNode): NormNode =
newTree(kind, n) |
Unless this is a comment just for documentation purposes I'm going to need more info then this. Not to be haphazard, but changes like this might change overload precedence, especially in edge cases. I'm not sure what binding rule is being violated here, and if that is actually a breakage in Nim. Looks like this potentially involves scope, distinct types, generics and varags which seems edge-casey. To flush out an issue we might need to really think about what the correct behavior should be. I believe there are pretty straight forward ways to determine if bindings are correct or not in general, but I can't really apply them here when it's not apparent what is going on. |
Maybe I should have been clearer, trying to compile the file To make things easier, the issue still occurs if More info: ...
result = a.convMatches - b.convMatches
if result != 0: return
result = cmpInheritancePenalty(a.inheritancePenalty, b.inheritancePenalty)
if a.calleeSym != nil and a.calleeSym.name.s == "newTree":
echo (result, a.inheritancePenalty, b.inheritancePenalty, a.calleeSym.typ, b.calleeSym.typ)
if result != 0: return
... Output of the
My guess is somehow the inheritance penalty is being delayed until after the converter call, which causes |
Alright thanks for clarifying. I'll take a closer look later. |
This fixes a logic error in #23870 The inheritance penalty should be -1 if there is no inheritance relationship. Not sure how to write a test case for this one honestly. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This fixes a logic error in nim-lang#23870 The inheritance penalty should be -1 if there is no inheritance relationship. Not sure how to write a test case for this one honestly. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
The test case diff is self explanatory