Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 22 additions & 5 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,17 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
if ff != nil:
result = typeRel(c, ff, a, flags)
of tyGenericInvocation:
var x = a.skipGenericAlias
var x = a
while x != nil:
if x.kind == tyAlias:
x = x.last
elif x.isGenericAlias:
if f[0] == x[0]:
break
else:
x = x.last
else:
break
if x.kind == tyGenericParam and x.len > 0:
x = x.last
let concpt = f.reduceToBase
Expand All @@ -1751,7 +1761,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
preventHack = true
x = x.last
# XXX: This is very hacky. It should be moved back into liftTypeParam
if x.kind in {tyGenericInst, tyArray} and
if x.kind in {tyArray} and
c.calleeSym != nil and
c.calleeSym.kind in {skProc, skFunc} and c.call != nil and not preventHack:
let inst = prepareMetatypeForSigmatch(c.c, c.bindings, c.call.info, f)
Expand Down Expand Up @@ -1807,10 +1817,12 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
else:
let key = f[i]
let old = lookup(c.bindings, key)
if old == nil:
if typeRel(c, key, x, flags) == isNone:
result = isNone
elif old == nil or typeRel(c, old, x, flags + {trDontBind}) > isNone:
put(c, key, x)
elif typeRel(c, old, x, flags + {trDontBind}) == isNone:
return isNone
else:
result = isNone
var depth = -1
if fobj != nil and aobj != nil and askip == fskip:
depth = isObjectSubtype(c, aobj, fobj, f)
Expand Down Expand Up @@ -1891,6 +1903,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
return isNone
if doBind: put(c, f, a)
return isGeneric
elif effectiveArgType.kind == tyOr:
for kid in effectiveArgType.kids:
if typeRel(c, f, kid, flags) >= isSubtype:
result = isGeneric
break
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