Skip to content
Draft
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
4 changes: 1 addition & 3 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,7 @@ proc cow(p: BProc; n: PNode) {.inline.} =
if n.kind == nkHiddenAddr: cowBracket(p, n[0])

template ignoreConv(e: PNode): bool =
let destType = e.typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink})
let srcType = e[1].typ.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink})
sameBackendTypePickyAliases(destType, srcType)
sameBackendTypePickyAliases(e.typ, e[1].typ)

proc genAddr(p: BProc, e: PNode, d: var TLoc) =
# careful 'addr(myptrToArray)' needs to get the ampersand:
Expand Down
9 changes: 8 additions & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,14 @@ proc isOpImpl(c: PContext, n: PNode, flags: TExprFlags): PNode =
if efExplain in flags:
m.diagnostics = @[]
m.diagnosticsEnabled = true
res = typeRel(m, t2, t1) >= isSubtype # isNone
let rel = typeRel(m, t2, t1)
res = rel >= isSubtype # isNone
if res and rel == isEqual and
not compareTypes(t1, t2,
flags = {ExactTypeDescValues,
PickyCAliases,
PickyBackendAliases}):
res = false
# `res = sameType(t1, t2)` would be wrong, e.g. for `int is (int|float)`

result = newIntNode(nkIntLit, ord(res))
Expand Down
3 changes: 2 additions & 1 deletion compiler/seminst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ proc sameInstantiation(a, b: TInstantiation): bool =
if not compareTypes(a.concreteTypes[i], b.concreteTypes[i],
flags = {ExactTypeDescValues,
ExactGcSafety,
PickyCAliases}): return
PickyCAliases,
PickyBackendAliases}): return
result = true
else:
result = false
Expand Down
3 changes: 2 additions & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ proc searchInstTypes*(g: ModuleGraph; key: PType): PType =
for j in FirstGenericParamAt..<key.kidsLen:
# XXX sameType is not really correct for nested generics?
if not compareTypes(inst[j], key[j],
flags = {ExactGenericParams, PickyCAliases}):
flags = {ExactGenericParams, PickyCAliases,
PickyBackendAliases}):
break matchType

return inst
Expand Down
8 changes: 7 additions & 1 deletion compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,11 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
c.flags = oldFlags

if x == y: return true
let aliasSkipSet = maybeSkipRange({tyAlias, tyInferred})
let aliasSkipSet = maybeSkipRange(
if PickyBackendAliases in c.flags:
{tyInferred}
else:
{tyAlias, tyInferred})
var a = skipTypes(x, aliasSkipSet)
while a.kind == tyUserTypeClass and tfResolved in a.flags:
a = skipTypes(a.last, aliasSkipSet)
Expand Down Expand Up @@ -1070,6 +1074,8 @@ proc sameBackendTypeIgnoreRange*(x, y: PType): bool =
result = sameTypeAux(x, y, c)

proc sameBackendTypePickyAliases*(x, y: PType): bool =
let x = x.skipTypes({tyVar, tyLent, tySink, tyOwned})
let y = y.skipTypes({tyVar, tyLent, tySink, tyOwned})
var c = initSameTypeClosure()
c.flags.incl {IgnoreTupleFields, IgnoreRangeShallow, PickyCAliases, PickyBackendAliases}
c.cmp = dcEqIgnoreDistinct
Expand Down
16 changes: 16 additions & 0 deletions tests/ccgbugs2/tcodegen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,19 @@ block: # importc type inheritance
doAssert(cast[cint](b) == 123)
var c = foo(b)
doAssert(cast[cint](c) == 123)


# bug #23765
Comment thread
ringabout marked this conversation as resolved.
type
X11[T, E] = object
m: T
B = X11[culonglong, cstring]
S = ref object of RootObj

proc j[T, E](m: X11[T, E]): T = discard
proc n(T: typedesc[SomeUnsignedInt]): X11[T, cstring] = discard
method call(client: S): uint64 {.base.} =
discard j(n(uint64))

var s = S()
discard s.call()
Loading