diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 03c5444fd7..0b07eaeb1d 100755 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1395,7 +1395,11 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) = toRope(magic)])) proc genConv(p: BProc, e: PNode, d: var TLoc) = - genCast(p, e, d) + if equalOrDistinctOf(e.typ, e.sons[1].typ) or + equalOrDistinctOf(e.sons[1].typ, e.typ): + expr(p, e.sons[1], d) + else: + genCast(p, e, d) proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) = var a: TLoc diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index 15b48fcb07..555d401ca3 100755 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -72,7 +72,7 @@ proc GetUniqueType*(key: PType): PType = if result == nil: IdTablePut(gTypeTable[k], key, key) result = key - of tyGenericInst, tyDistinct, tyOrdinal: + of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, tyConst, tyIter: result = GetUniqueType(lastSon(key)) of tyProc: nil @@ -116,9 +116,8 @@ proc makeCString*(s: string): PRope = # further information. const MaxLineLength = 64 - var res: string result = nil - res = "\"" + var res = "\"" for i in countup(0, len(s) - 1): if (i + 1) mod MaxLineLength == 0: add(res, '\"') @@ -132,9 +131,8 @@ proc makeCString*(s: string): PRope = proc makeLLVMString*(s: string): PRope = const MaxLineLength = 64 - var res: string result = nil - res = "c\"" + var res = "c\"" for i in countup(0, len(s) - 1): if (i + 1) mod MaxLineLength == 0: app(result, toRope(res)) diff --git a/compiler/parser.nim b/compiler/parser.nim index df21c99167..8fbc44ebdc 100755 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -1316,6 +1316,7 @@ proc complexOrSimpleStmt(p: var TParser): PNode = of tkConverter: result = parseRoutine(p, nkConverterDef) of tkType: result = parseSection(p, nkTypeSection, parseTypeDef) of tkConst: result = parseSection(p, nkConstSection, parseConstant) + of tkLet: result = parseSection(p, nkLetSection, parseConstant) of tkWhen: result = parseIfOrWhen(p, nkWhenStmt) of tkVar: result = parseSection(p, nkVarSection, parseVariable) else: result = simpleStmt(p) @@ -1379,7 +1380,7 @@ proc parseString(s: string, filename: string = "", line: int = 0): PNode = var stream = LLStreamOpen(s) stream.lineOffset = line - var parser : TParser + var parser: TParser OpenParser(parser, filename, stream) result = parser.parseAll diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index da64db9a9f..95808b85af 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -378,6 +378,10 @@ proc isAssignable(c: PContext, n: PNode): TAssignableResult = # Object and tuple conversions are still addressable, so we skip them if skipTypes(n.typ, abstractPtrs).kind in {tyOpenArray, tyTuple, tyObject}: result = isAssignable(c, n.sons[1]) + elif equalOrDistinctOf(n.typ, n.sons[1].typ) or + equalOrDistinctOf(n.sons[1].typ, n.typ): + # types that are equal modulo distinction preserve l-value: + result = isAssignable(c, n.sons[1]) of nkHiddenDeref, nkDerefExpr: result = arLValue of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr: