diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim index aac97cdf33..67cd6e1b28 100644 --- a/compiler/sighashes.nim +++ b/compiler/sighashes.nim @@ -143,7 +143,11 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]; conf: Confi # backend spelling instead of collapsing into the generic Nim builtin: c &= char(t.kind) if t.sym != nil and {sfImportc, sfExportc} * t.sym.flags != {}: - c.hashSym(t.sym) + # Aliases inherit the external name, but have a different symbol. + if t.sym.loc.snippet != "": + c &= t.sym.loc.snippet + else: + c.hashSym(t.sym) of tyObject, tyEnum: if t.typeInst != nil: # prevent against infinite recursions here, see bug #8883: diff --git a/tests/ccgbugs/mseq_importc_alias.nim b/tests/ccgbugs/mseq_importc_alias.nim new file mode 100644 index 0000000000..5b3f97747d --- /dev/null +++ b/tests/ccgbugs/mseq_importc_alias.nim @@ -0,0 +1,5 @@ +proc resizeCints*(s: var seq[cint], n: int) = + s.setLen(n) + +proc cintLen*(s: seq[cint]): int = + result = s.len diff --git a/tests/ccgbugs/tseq_importc_alias_crossmod.nim b/tests/ccgbugs/tseq_importc_alias_crossmod.nim new file mode 100644 index 0000000000..a4c94d2b2e --- /dev/null +++ b/tests/ccgbugs/tseq_importc_alias_crossmod.nim @@ -0,0 +1,15 @@ +discard """ + action: run + targets: "c cpp" +""" + +import mseq_importc_alias + +type CIntAlias = cint + +var fds: seq[CIntAlias] +doAssert cintLen(@[1.cint, 2.cint]) == 2 +doAssert cintLen(fds) == 0 +resizeCints(fds, 3) +fds[1] = CIntAlias(7) +doAssert cintLen(fds) == 3 diff --git a/tests/ccgbugs/tseq_importc_alias_mangle.nim b/tests/ccgbugs/tseq_importc_alias_mangle.nim new file mode 100644 index 0000000000..a6a9074ec4 --- /dev/null +++ b/tests/ccgbugs/tseq_importc_alias_mangle.nim @@ -0,0 +1,20 @@ +discard """ + action: run + targets: "c cpp" +""" + +type CIntAlias = cint + +var x: (cint,) = (1.cint,) +var y: (CIntAlias,) = x +x = y +doAssert x[0] == 1.cint + +var a: seq[cint] +var b: seq[CIntAlias] +a.add 1.cint +a.add 2.cint +b = a +a = b +doAssert a[0] == 1.cint +doAssert b[1] == CIntAlias(2) diff --git a/tests/ic/timportcalias.nim b/tests/ic/timportcalias.nim new file mode 100644 index 0000000000..2f6c20f4b5 --- /dev/null +++ b/tests/ic/timportcalias.nim @@ -0,0 +1,7 @@ +import ../ccgbugs/mseq_importc_alias + +type CIntAlias = cint + +var values: seq[CIntAlias] +resizeCints(values, 2) +doAssert cintLen(values) == 2