Skip to content

Commit 1bd3ccb

Browse files
committed
clearify the condition
1 parent 19d58d8 commit 1bd3ccb

File tree

5 files changed

+12
-27
lines changed

5 files changed

+12
-27
lines changed

compiler/ccgtypes.nim

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -700,15 +700,8 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin
700700
return
701701
case t.kind
702702
of tyRef, tyPtr, tyVar, tyLent:
703-
var star: string
704-
if t.kind in {tyVar} and tfVarIsPtr notin origTyp.flags and
705-
compileToCpp(m):
706-
if isImportedCppType(t.skipTypes({tyVar})):
707-
star = ""
708-
else:
709-
star = "&"
710-
else:
711-
star = "*"
703+
var star = if t.kind in {tyVar} and tfVarIsPtr notin origTyp.flags and
704+
compileToCpp(m): "&" else: "*"
712705
var et = origTyp.skipTypes(abstractInst).lastSon
713706
var etB = et.skipTypes(abstractInst)
714707
if mapType(m.config, t, kind) == ctPtrToArray and (etB.kind != tyOpenArray or kind == skParam):

compiler/cgen.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,10 @@ proc constructLoc(p: BProc, loc: var TLoc, isTemp = false) =
491491
nilLoc.r = rope("NIM_NIL")
492492
genRefAssign(p, loc, nilLoc)
493493
else:
494-
if p.module.compileToCpp and typ.kind == tyVar and isImportedCppType(typ.skipTypes({tyVar})):
495-
return
494+
if typ.kind == tyVar:
495+
let tt = typ.skipTypes({tyVar})
496+
if isImportedType(tt) and tfRequiresInit in tt.flags:
497+
return
496498
linefmt(p, cpsStmts, "$1 = ($2)0;$n", [rdLoc(loc),
497499
getTypeDesc(p.module, typ, mapTypeChooser(loc))])
498500
else:

compiler/semstmts.nim

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,12 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
716716
let actualType = v.typ.skipTypes({tyGenericInst, tyAlias,
717717
tyUserTypeClassInst})
718718
if actualType.kind in {tyObject, tyDistinct} and
719-
actualType.requiresInit and not (sfImportc in actualType.sym.flags):
719+
actualType.requiresInit:
720720
# imported type use requiresInit pragma prevent implicit initialization
721-
defaultConstructionError(c, v.typ, v.info)
721+
if (tfRequiresInit in actualType.flags and sfImportc in actualType.sym.flags):
722+
discard
723+
else:
724+
defaultConstructionError(c, v.typ, v.info)
722725
else:
723726
checkNilable(c, v)
724727
# allow let to not be initialised if imported from C:

tests/cpp/t17982.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type
99
proc initString*(): String
1010
{.importcpp: "std::string()", header: "string".}
1111

12-
proc append*(this: var String, str: String): var String
12+
proc append*(this: var String, str: String): String
1313
# bug seems to trigger when `#`, `@`, or `$1` is used inside `importcpp`
1414
{.importcpp: "#.append(@)", header: "string", discardable.} # <- changed from `importcpp: "append"`
1515

tests/cpp/tatomic.nim

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)