fixes #23445; fixes #23418 [backport] (#23699)

(cherry picked from commit 56c95758b2)
This commit is contained in:
Andreas Rumpf
2024-06-09 08:16:05 +02:00
committed by narimiran
parent 40ee3a950e
commit 8bb9823fde
3 changed files with 40 additions and 1 deletions

View File

@@ -388,6 +388,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
for j in 1..<result.typ.len:
entry.concreteTypes[i] = result.typ[j]
inc i
#echo "INSTAN ", fn.name.s, " ", typeToString(result.typ), " ", entry.concreteTypes.len
if tfTriggersCompileTime in result.typ.flags:
incl(result.flags, sfCompileTime)
n[genericParamsPos] = c.graph.emptyNode
@@ -410,7 +411,9 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
if result.magic notin {mSlice, mTypeOf}:
# 'toOpenArray' is special and it is allowed to return 'openArray':
paramsTypeCheck(c, result.typ)
#echo "INSTAN ", fn.name.s, " ", typeToString(result.typ), " <-- NEW PROC!", " ", entry.concreteTypes.len
else:
#echo "INSTAN ", fn.name.s, " ", typeToString(result.typ), " <-- CACHED! ", typeToString(oldPrc.typ), " ", entry.concreteTypes.len
result = oldPrc
popProcCon(c)
popInfoContext(c.config)

View File

@@ -1326,9 +1326,17 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
result = sameTypeOrNilAux(a[0], b[0], c) and
sameValue(a.n[0], b.n[0]) and
sameValue(a.n[1], b.n[1])
of tyGenericInst, tyAlias, tyInferred, tyIterable:
of tyAlias, tyInferred, tyIterable:
cycleCheck()
result = sameTypeAux(a.lastSon, b.lastSon, c)
of tyGenericInst:
# BUG #23445
# The type system must distinguish between `T[int] = object #[empty]#`
# and `T[float] = object #[empty]#`!
cycleCheck()
for ff, aa in underspecifiedPairs(a, b, 1, -1):
if not sameTypeAux(ff, aa, c): return false
result = sameTypeAux(a.skipModifier, b.skipModifier, c)
of tyNone: result = false
of tyConcept:
result = exprStructuralEquivalent(a.n, b.n)

View File

@@ -0,0 +1,28 @@
# bug #23418
template mapIt*(x: untyped): untyped =
type OutType {.gensym.} = typeof(x) #typeof(x, typeOfProc)
newSeq[OutType](5)
type F[E] = object
proc start(v: int): F[(ValueError,)] = discard
proc stop(v: int): F[tuple[]] = discard
assert $typeof(mapIt(start(9))) == "seq[F[(ValueError,)]]"
assert $typeof(mapIt(stop(9))) == "seq[F[tuple[]]]"
# bug #23445
type F2[T; I: static int] = distinct int
proc start2(v: int): F2[void, 22] = discard
proc stop2(v: int): F2[void, 33] = discard
var a = mapIt(start2(5))
assert $type(a) == "seq[F2[system.void, 22]]", $type(a)
var b = mapIt(stop2(5))
assert $type(b) == "seq[F2[system.void, 33]]", $type(b)