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
15 changes: 14 additions & 1 deletion compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,20 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
withoutShallowFlags:
for ff, aa in underspecifiedPairs(rhs, lhs, 1, -1):
if not sameTypeAux(ff, aa, c): return false
return true
if lhs.base.last.kind == tyOr:
# issue #25346
# In following code, both types of parameters of instanciated `foo` are `Foo[char]`,
# but they are different types.
#
# type
# Foo[T] = seq[T] or set[T]
#
# proc foo[T](x: Foo[T]) = discard
# foo(@['1', '2'])
# foo({'1', '2'})
return sameTypeAux(lhs.skipModifier, rhs.skipModifier, c)
else:
return true

case a.kind
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring,
Expand Down
16 changes: 16 additions & 0 deletions tests/generics/t25346.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# issue #25346

type
Foo[T] = seq[T] or set[T]

proc foo[T](x: Foo[T]) = discard
foo(@['a', 'b'])
foo({'a', 'b'})

type
Bar[T] = seq[T] or ptr UncheckedArray[T]

proc bar[T](x: Bar[T]) = discard
var x = @[1, 2]
bar(x)
bar(cast[ptr UncheckedArray[int]](addr x[0]))