* hangle static generic params when used in the importcpp pragma

* importcpp works for generic types with fields; fixes #6415

* revert a too agressive safety check that ended up breaking the tests
This commit is contained in:
zah 2018-03-08 16:10:45 +02:00 • committed by Andreas Rumpf
commit cbd059aa85
4 changed files with 71 additions and 6 deletions

View file

@ -617,8 +617,10 @@ proc scanCppGenericSlot(pat: string, cursor, outIdx, outStars: var int): bool =
return false
proc resolveStarsInCppType(typ: PType, idx, stars: int): PType =
# XXX: we should catch this earlier and report it as a semantic error
if idx >= typ.len: internalError "invalid apostrophe type parameter index"
# Make sure the index refers to one of the generic params of the type.
# XXX: we should catch this earlier and report it as a semantic error.
if idx >= typ.len:
internalError "invalid apostrophe type parameter index"
result = typ.sons[idx]
for i in 1..stars:
@ -820,6 +822,9 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
let typeInSlot = resolveStarsInCppType(origTyp, idx + 1, stars)
if typeInSlot == nil or typeInSlot.kind == tyVoid:
result.add(~"void")
elif typeInSlot.kind == tyStatic:
internalAssert typeInSlot.n != nil
result.add typeInSlot.n.renderTree
else:
result.add getTypeDescAux(m, typeInSlot, check)
else:

View file

@ -632,16 +632,18 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
else:
typ = semTypeNode(c, n.sons[length-2], nil)
propagateToOwner(rectype, typ)
let rec = rectype.sym
var fieldOwner = if c.inGenericContext > 0: c.getCurrOwner
else: rectype.sym
for i in countup(0, sonsLen(n)-3):
var f = semIdentWithPragma(c, skField, n.sons[i], {sfExported})
suggestSym(n.sons[i].info, f, c.graph.usageSym)
f.typ = typ
f.position = pos
if (rec != nil) and ({sfImportc, sfExportc} * rec.flags != {}) and
(f.loc.r == nil):
if fieldOwner != nil and
{sfImportc, sfExportc} * fieldOwner.flags != {} and
f.loc.r == nil:
f.loc.r = rope(f.name.s)
f.flags = f.flags + ({sfImportc, sfExportc} * rec.flags)
f.flags = f.flags + ({sfImportc, sfExportc} * fieldOwner.flags)
inc(pos)
if containsOrIncl(check, f.name.id):
localError(n.sons[i].info, errAttemptToRedefine, f.name.s)