Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,21 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
return isNone
if doBind: put(c, f, a)
return isGeneric
elif effectiveArgType.kind == tyOr:
let oldInheritancePenalty = c.inheritancePenalty
var
bestPenatly = maxInheritancePenalty
bestMatch = isNone
for kid in effectiveArgType.kids:
let x = typeRel(c, f, kid, flags)
if x > bestMatch:
bestMatch = x
bestPenatly = c.inheritancePenalty
c.inheritancePenalty = oldInheritancePenalty
c.inheritancePenalty = oldInheritancePenalty
if bestMatch > isNone:
c.inheritancePenalty = bestPenatly
result = bestMatch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Instead the later disambiguation phase should pick it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the later phases actually don't handle tyOr precisely. You're right though, if I made this unique I probably shouldn't have. I think the failures are coming from binding issues. Might be a deeper problem here unfortunately.

else:
return isNone
of tyUserTypeClassInst, tyUserTypeClass:
Expand Down
13 changes: 13 additions & 0 deletions tests/typerel/tsigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ block: # bug #13618

doAssert test(^1) == 1
doAssert test(1) == 1

block: # #25174
type Foo = object
type Bar = object
type Quz = object

proc bar[T: Foo | Bar](x: T): string =
return $typeof(T)
proc bar[T: object](x: T): string =
return $typeof(T)
doAssert bar(Foo()) == "Foo"
doAssert bar(Bar()) == "Bar"
doAssert bar(Quz()) == "Quz"
Loading