* fixes #16069; refs https://github.com/nim-lang/RFCs/issues/257 [backport:1.2] [backport:1.4] * make tests green again
This commit is contained in:
parent
1d14b2c9e6
commit
d306a04466
8 changed files with 29 additions and 15 deletions
|
|
@ -1122,7 +1122,7 @@ proc safeLen*(n: PNode): int {.inline.} =
|
||||||
|
|
||||||
proc safeArrLen*(n: PNode): int {.inline.} =
|
proc safeArrLen*(n: PNode): int {.inline.} =
|
||||||
## works for array-like objects (strings passed as openArray in VM).
|
## works for array-like objects (strings passed as openArray in VM).
|
||||||
if n.kind in {nkStrLit..nkTripleStrLit}:result = n.strVal.len
|
if n.kind in {nkStrLit..nkTripleStrLit}: result = n.strVal.len
|
||||||
elif n.kind in {nkNone..nkFloat128Lit}: result = 0
|
elif n.kind in {nkNone..nkFloat128Lit}: result = 0
|
||||||
else: result = n.len
|
else: result = n.len
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -881,6 +881,7 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) =
|
||||||
[rdLoc(test), strLit, raiseInstr(p)])
|
[rdLoc(test), strLit, raiseInstr(p)])
|
||||||
|
|
||||||
proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) =
|
proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) =
|
||||||
|
assert e[0].kind == nkDotExpr
|
||||||
if optFieldCheck in p.options:
|
if optFieldCheck in p.options:
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
genRecordFieldAux(p, e[0], d, a)
|
genRecordFieldAux(p, e[0], d, a)
|
||||||
|
|
|
||||||
|
|
@ -685,6 +685,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
|
||||||
of nkBracketExpr: result = foldArrayAccess(m, n, idgen, g)
|
of nkBracketExpr: result = foldArrayAccess(m, n, idgen, g)
|
||||||
of nkDotExpr: result = foldFieldAccess(m, n, idgen, g)
|
of nkDotExpr: result = foldFieldAccess(m, n, idgen, g)
|
||||||
of nkCheckedFieldExpr:
|
of nkCheckedFieldExpr:
|
||||||
|
assert n[0].kind == nkDotExpr
|
||||||
result = foldFieldAccess(m, n[0], idgen, g)
|
result = foldFieldAccess(m, n[0], idgen, g)
|
||||||
of nkStmtListExpr:
|
of nkStmtListExpr:
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
|
||||||
|
|
@ -1002,6 +1002,11 @@ proc transform(c: PTransf, n: PNode): PNode =
|
||||||
return n
|
return n
|
||||||
of nkExceptBranch:
|
of nkExceptBranch:
|
||||||
result = transformExceptBranch(c, n)
|
result = transformExceptBranch(c, n)
|
||||||
|
of nkCheckedFieldExpr:
|
||||||
|
result = transformSons(c, n)
|
||||||
|
if result[0].kind != nkDotExpr:
|
||||||
|
# simplfied beyond a dot expression --> simplify further.
|
||||||
|
result = result[0]
|
||||||
else:
|
else:
|
||||||
result = transformSons(c, n)
|
result = transformSons(c, n)
|
||||||
when false:
|
when false:
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,6 @@ proc stupidStmtListExpr*(n: PNode): bool =
|
||||||
proc dontInlineConstant*(orig, cnst: PNode): bool {.inline.} =
|
proc dontInlineConstant*(orig, cnst: PNode): bool {.inline.} =
|
||||||
# symbols that expand to a complex constant (array, etc.) should not be
|
# symbols that expand to a complex constant (array, etc.) should not be
|
||||||
# inlined, unless it's the empty array:
|
# inlined, unless it's the empty array:
|
||||||
result = orig.kind == nkSym and
|
result = orig.kind != cnst.kind and
|
||||||
cnst.kind in {nkCurly, nkPar, nkTupleConstr, nkBracket, nkObjConstr} and
|
cnst.kind in {nkCurly, nkPar, nkTupleConstr, nkBracket, nkObjConstr} and
|
||||||
cnst.len > ord(cnst.kind == nkObjConstr)
|
cnst.len > ord(cnst.kind == nkObjConstr)
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ var
|
||||||
lvalue
|
lvalue
|
||||||
lnext
|
lnext
|
||||||
_
|
_
|
||||||
`=copy`(lresult, [123])
|
lresult = @[123]
|
||||||
_ = (
|
_ = (
|
||||||
let blitTmp = lresult
|
let blitTmp = lresult
|
||||||
blitTmp, ";")
|
blitTmp, ";")
|
||||||
|
|
|
||||||
|
|
@ -102,17 +102,6 @@ block:
|
||||||
let a2 = (11,)
|
let a2 = (11,)
|
||||||
doAssert byLent(a2) == (11,)
|
doAssert byLent(a2) == (11,)
|
||||||
|
|
||||||
block:
|
|
||||||
when (defined(c) or defined(cpp)) and defined(release):
|
|
||||||
discard # probably not a bug since optimizer is free to pass by value, and `unsafeAddr` is used
|
|
||||||
else:
|
|
||||||
var a = @[12]
|
|
||||||
doAssert byPtr(a)[] == @[12]
|
|
||||||
let a2 = [13]
|
|
||||||
doAssert byPtr(a2)[] == [13]
|
|
||||||
let a3 = 14
|
|
||||||
doAssert byPtr(a3)[] == 14
|
|
||||||
|
|
||||||
block:
|
block:
|
||||||
proc byLent2[T](a: seq[T]): lent T = a[1]
|
proc byLent2[T](a: seq[T]): lent T = a[1]
|
||||||
var a = @[20,21,22]
|
var a = @[20,21,22]
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ discard """
|
||||||
(name: "hello")
|
(name: "hello")
|
||||||
(-1, 0)
|
(-1, 0)
|
||||||
(FirstName: "James", LastName: "Franco")
|
(FirstName: "James", LastName: "Franco")
|
||||||
|
[1, 2, 3]
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -74,4 +75,21 @@ static: # issue #11861
|
||||||
|
|
||||||
static: # issue #15662
|
static: # issue #15662
|
||||||
proc a(T: typedesc) = echo T.type
|
proc a(T: typedesc) = echo T.type
|
||||||
a((int, int))
|
a((int, int))
|
||||||
|
|
||||||
|
# bug #16069
|
||||||
|
type
|
||||||
|
E = enum
|
||||||
|
val1, val2
|
||||||
|
Obj = object
|
||||||
|
case k: E
|
||||||
|
of val1:
|
||||||
|
x: array[3, int]
|
||||||
|
of val2:
|
||||||
|
y: uint32
|
||||||
|
|
||||||
|
const
|
||||||
|
foo = [1, 2, 3]
|
||||||
|
arr = Obj(k: val1, x: foo)
|
||||||
|
|
||||||
|
echo arr.x
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue