diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-10-16 02:12:41 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-10-16 02:21:28 +0300 |
commit | 2efdf3df81fc1a451f4444e822a870c59e27e586 (patch) | |
tree | 2e693677d02842dcd4dc980b6f10f7b846630acd | |
parent | 3c9e3a6a716326c48e509e7b09596e2a1bf900fa (diff) | |
download | Nim-2efdf3df81fc1a451f4444e822a870c59e27e586.tar.gz |
fixes #106
-rwxr-xr-x | compiler/ccgexprs.nim | 4 | ||||
-rwxr-xr-x | compiler/cgen.nim | 2 | ||||
-rwxr-xr-x | tests/run/tarray2.nim | 32 |
3 files changed, 25 insertions, 13 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index d10b37432..d6666d88b 100755 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -223,7 +223,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = # little HACK to support the new 'var T' as return type: lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) return - var ty = skipTypes(dest.t, abstractVarRange) + var ty = skipTypes(dest.t, abstractRange) case ty.kind of tyRef: genRefAssign(p, dest, src, flags) @@ -282,7 +282,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = else: lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCString, - tyInt..tyUInt64, tyRange: + tyInt..tyUInt64, tyRange, tyVar: lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) else: InternalError("genAssignment(" & $ty.kind & ')') diff --git a/compiler/cgen.nim b/compiler/cgen.nim index ffd9babde..0e0962936 100755 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -271,7 +271,7 @@ proc resetLoc(p: BProc, loc: var TLoc) = genObjectInit(p, cpsStmts, loc.t, loc, true) proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) = - if not isComplexValueType(skipTypes(loc.t, abstractVarRange)): + if not isComplexValueType(skipTypes(loc.t, abstractRange)): lineF(p, section, "$1 = 0;$n", [rdLoc(loc)]) else: lineF(p, section, "memset((void*)$1, 0, sizeof($2));$n", diff --git a/tests/run/tarray2.nim b/tests/run/tarray2.nim index 048f51795..b6adabb45 100755 --- a/tests/run/tarray2.nim +++ b/tests/run/tarray2.nim @@ -1,24 +1,36 @@ discard """ file: "tarray2.nim" - output: "[16, 25, 36]" + output: "[4, 5, 6]\n\n[16, 25, 36]\n\n[16, 25, 36]" """ -# simple check for one dimensional arrays - -type - TMyArray = array[0..2, int] - -proc mul(a, b: TMyarray): TMyArray = +# simple check for one dimensional arrays + +type + TMyArray = array[0..2, int] + + TObj = object + arr: TMyarray + +proc mul(a, b: TMyarray): TMyArray = result = a for i in 0..len(a)-1: result[i] = a[i] * b[i] var - x, y, z: TMyArray - + x, y: TMyArray + o: TObj + +proc varArr1(x: var TMyArray): var TMyArray = x +proc varArr2(x: var TObj): var TMyArray = x.arr + x = [ 4, 5, 6 ] +echo repr(varArr1(x)) + y = x echo repr(mul(x, y)) -#OUT [16, 25, 36] +o.arr = mul(x, y) +echo repr(varArr2(o)) + +#OUT [16, 25, 36] |