Skip to content

Commit

Permalink
fixes #16246 (#18800)
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq authored Sep 4, 2021
1 parent b3ad68e commit e8dad48
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler/seminst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ proc sameInstantiation(a, b: TInstantiation): bool =
for i in 0..a.concreteTypes.high:
if not compareTypes(a.concreteTypes[i], b.concreteTypes[i],
flags = {ExactTypeDescValues,
ExactGcSafety}): return
ExactGcSafety,
PickyCAliases}): return
result = true

proc genericCacheGet(g: ModuleGraph; genericSym: PSym, entry: TInstantiation;
Expand Down
2 changes: 1 addition & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ proc searchInstTypes*(g: ModuleGraph; key: PType): PType =
for j in 1..high(key.sons):
# XXX sameType is not really correct for nested generics?
if not compareTypes(inst[j], key[j],
flags = {ExactGenericParams}):
flags = {ExactGenericParams, PickyCAliases}):
break matchType

return inst
Expand Down
8 changes: 8 additions & 0 deletions compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ type
ExactConstraints
ExactGcSafety
AllowCommonBase
PickyCAliases # be picky about the distinction between 'cint' and 'int32'

TTypeCmpFlags* = set[TTypeCmpFlag]

Expand Down Expand Up @@ -1144,6 +1145,13 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring,
tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid:
result = sameFlags(a, b)
if result and PickyCAliases in c.flags:
# additional requirement for the caching of generics for importc'ed types:
# the symbols must be identical too:
let symFlagsA = if a.sym != nil: a.sym.flags else: {}
let symFlagsB = if b.sym != nil: b.sym.flags else: {}
if (symFlagsA+symFlagsB) * {sfImportc, sfExportc} != {}:
result = symFlagsA == symFlagsB
of tyStatic, tyFromExpr:
result = exprStructuralEquivalent(a.n, b.n) and sameFlags(a, b)
if result and a.len == b.len and a.len == 1:
Expand Down
11 changes: 11 additions & 0 deletions tests/arc/tarcmisc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,14 @@ proc putValue[T](n: T) =
echo b.n

useForward()


# bug #16246

proc testWeirdTypeAliases() =
var values = newSeq[cuint](8)
# var values: seq[cuint] does not produce codegen error
var drawCb = proc(): seq[uint32] =
result = newSeq[uint32](10)

testWeirdTypeAliases()

0 comments on commit e8dad48

Please sign in to comment.