Skip to content

Commit

Permalink
fixes #9578 (#11176)
Browse files Browse the repository at this point in the history
* fixes #9578

* fixed and expanded test
  • Loading branch information
jcosborn authored and Araq committed May 6, 2019
1 parent 0ecaaa8 commit b1091f8
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 76 additions & 0 deletions tests/ccgbugs/t9578.nim
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/ccgbugs/xarray9578.nim
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions tests/ccgbugs/xoa9578.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import t9578

proc testOpenArray*(x: var openArray[mytype]) =
f(x[0].addr)
7 changes: 7 additions & 0 deletions tests/ccgbugs/xseq9578.nim
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions tests/ccgbugs/xtuple9578.nim
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions tests/ccgbugs/xua9578.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b1091f8

Please sign in to comment.