Skip to content

Commit 56c9575

Browse files
authored
fixes #23445; fixes #23418 [backport] (#23699)
1 parent c7ee161 commit 56c9575

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

compiler/seminst.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TypeMapping,
396396
for _, param in paramTypes(result.typ):
397397
entry.concreteTypes[i] = param
398398
inc i
399+
#echo "INSTAN ", fn.name.s, " ", typeToString(result.typ), " ", entry.concreteTypes.len
399400
if tfTriggersCompileTime in result.typ.flags:
400401
incl(result.flags, sfCompileTime)
401402
n[genericParamsPos] = c.graph.emptyNode
@@ -424,7 +425,9 @@ proc generateInstance(c: PContext, fn: PSym, pt: TypeMapping,
424425
if result.magic notin {mSlice, mTypeOf}:
425426
# 'toOpenArray' is special and it is allowed to return 'openArray':
426427
paramsTypeCheck(c, result.typ)
428+
#echo "INSTAN ", fn.name.s, " ", typeToString(result.typ), " <-- NEW PROC!", " ", entry.concreteTypes.len
427429
else:
430+
#echo "INSTAN ", fn.name.s, " ", typeToString(result.typ), " <-- CACHED! ", typeToString(oldPrc.typ), " ", entry.concreteTypes.len
428431
result = oldPrc
429432
popProcCon(c)
430433
popInfoContext(c.config)

compiler/types.nim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,9 +1316,17 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
13161316
result = sameTypeOrNilAux(a.elementType, b.elementType, c) and
13171317
sameValue(a.n[0], b.n[0]) and
13181318
sameValue(a.n[1], b.n[1])
1319-
of tyGenericInst, tyAlias, tyInferred, tyIterable:
1319+
of tyAlias, tyInferred, tyIterable:
13201320
cycleCheck()
13211321
result = sameTypeAux(a.skipModifier, b.skipModifier, c)
1322+
of tyGenericInst:
1323+
# BUG #23445
1324+
# The type system must distinguish between `T[int] = object #[empty]#`
1325+
# and `T[float] = object #[empty]#`!
1326+
cycleCheck()
1327+
for ff, aa in underspecifiedPairs(a, b, 1, -1):
1328+
if not sameTypeAux(ff, aa, c): return false
1329+
result = sameTypeAux(a.skipModifier, b.skipModifier, c)
13221330
of tyNone: result = false
13231331
of tyConcept:
13241332
result = exprStructuralEquivalent(a.n, b.n)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# bug #23418
2+
3+
template mapIt*(x: untyped): untyped =
4+
type OutType {.gensym.} = typeof(x) #typeof(x, typeOfProc)
5+
newSeq[OutType](5)
6+
7+
type F[E] = object
8+
9+
proc start(v: int): F[(ValueError,)] = discard
10+
proc stop(v: int): F[tuple[]] = discard
11+
12+
assert $typeof(mapIt(start(9))) == "seq[F[(ValueError,)]]"
13+
assert $typeof(mapIt(stop(9))) == "seq[F[tuple[]]]"
14+
15+
# bug #23445
16+
17+
type F2[T; I: static int] = distinct int
18+
19+
proc start2(v: int): F2[void, 22] = discard
20+
proc stop2(v: int): F2[void, 33] = discard
21+
22+
var a = mapIt(start2(5))
23+
24+
assert $type(a) == "seq[F2[system.void, 22]]", $type(a)
25+
26+
var b = mapIt(stop2(5))
27+
28+
assert $type(b) == "seq[F2[system.void, 33]]", $type(b)

0 commit comments

Comments
 (0)