* fixes #9578

* fixed and expanded test
This commit is contained in:
jcosborn
2019-05-06 02:34:03 -05:00
committed by Andreas Rumpf
parent 0ecaaa85e9
commit b1091f85d4
7 changed files with 109 additions and 0 deletions

View File

@@ -995,6 +995,7 @@ proc genBracketExpr(p: BProc; n: PNode; d: var TLoc) =
of tyCString: genCStringElem(p, n, n.sons[0], n.sons[1], d)
of tyTuple: genTupleElem(p, n, d)
else: internalError(p.config, n.info, "expr(nkBracketExpr, " & $ty.kind & ')')
discard getTypeDesc(p.module, n.typ)
proc isSimpleExpr(n: PNode): bool =
# calls all the way down --> can stay expression based

76
tests/ccgbugs/t9578.nim Normal file
View File

@@ -0,0 +1,76 @@
discard """
output: '''
@[(v: -1), (v: 2), (v: 3)]
@[(v: -1), (v: 2), (v: 3)]
[(v: -1), (v: 2), (v: 3)]
[(v: -1), (v: 2), (v: 3)]
((v: -1), (v: 2), (v: 3))
((v: -1), (v: 2), (v: 3))
@[(v: -1), (v: 2), (v: 3)]
@[(v: -1), (v: 2), (v: 3)]
@[(v: -1), (v: 2), (v: 3)]
'''
"""
type mytype* = object
v:int
proc f*(x:ptr mytype) = x.v = -1
func g(x:int):mytype = mytype(v:x)
import xseq9578
block:
var x = @[1.g,2.g,3.g]
testSeq(x)
echo x
block:
var x = @[1.g,2.g,3.g]
var y = addr x
testSeq2(y)
echo x
import xarray9578
block:
var x = [1.g,2.g,3.g]
testArray(x)
echo x
block:
var x = [1.g,2.g,3.g]
var y = addr x
testArray2(y)
echo x
import xtuple9578
block:
var x = (1.g,2.g,3.g)
testTuple(x)
echo x
block:
var x = (1.g,2.g,3.g)
var y = addr x
testTuple2(y)
echo x
import xoa9578
block:
var x = @[1.g,2.g,3.g]
testOpenArray(x)
echo x
import xua9578
block:
var x = @[1.g,2.g,3.g]
var y = cast[ptr UncheckedArray[mytype]](addr x[0])
testUncheckedArray(y[])
echo x
block:
var x = @[1.g,2.g,3.g]
var y = cast[ptr UncheckedArray[mytype]](addr x[0])
testUncheckedArray2(y)
echo x

View File

@@ -0,0 +1,7 @@
import t9578
proc testArray*(x: var array[3,mytype]) =
f(x[0].addr)
proc testArray2*(x: var ptr array[3,mytype]) =
f(x[0].addr)

View File

@@ -0,0 +1,4 @@
import t9578
proc testOpenArray*(x: var openArray[mytype]) =
f(x[0].addr)

View File

@@ -0,0 +1,7 @@
import t9578
proc testSeq*(x: var seq[mytype]) =
f(x[0].addr)
proc testSeq2*(x: var ptr seq[mytype]) =
f(x[0].addr)

View File

@@ -0,0 +1,7 @@
import t9578
proc testTuple*(x: var tuple[a:mytype,b:mytype,c:mytype]) =
f(x[0].addr)
proc testTuple2*(x: var ptr tuple[a:mytype,b:mytype,c:mytype]) =
f(x[0].addr)

View File

@@ -0,0 +1,7 @@
import t9578
proc testUncheckedArray*(x: var UncheckedArray[mytype]) =
f(x[0].addr)
proc testUncheckedArray2*(x: var ptr UncheckedArray[mytype]) =
f(x[0].addr)