diff options
author | Araq <rumpf_a@web.de> | 2011-06-05 13:59:41 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-06-05 13:59:41 +0200 |
commit | 958961bd8d0bc699c6301984a706c5d182079c71 (patch) | |
tree | aafcf4fdf3d479f334146094f6240dac7e288dc8 | |
parent | e5eb36e4722dd333dd48cfcf5c54fb6549fe4a46 (diff) | |
download | Nim-958961bd8d0bc699c6301984a706c5d182079c71.tar.gz |
overloading of [] for derefence operation should be possible now
-rwxr-xr-x | compiler/ccgexprs.nim | 4 | ||||
-rwxr-xr-x | compiler/semexprs.nim | 8 | ||||
-rw-r--r-- | tests/accept/run/tgenericassign.nim | 24 |
3 files changed, 31 insertions, 5 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 3f3a60b7a..2cb99d3a9 100755 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -772,8 +772,8 @@ proc genEcho(p: BProc, n: PNode) = for i in countup(1, n.len-1): initLocExpr(p, n.sons[i], a) appf(args, ", ($1)->data", [rdLoc(a)]) - appcg(p, cpsStmts, "printf(\"" & repeatStr(n.len-1, "%s") & - "\\n\"$1);$n", [args]) + appcg(p, cpsStmts, "printf($1$2);$n", [ + makeCString(repeatStr(n.len-1, "%s") & tnl), args]) proc genCall(p: BProc, t: PNode, d: var TLoc) = var op, a: TLoc diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 38db93988..17c4b7427 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -726,13 +726,15 @@ proc semDeref(c: PContext, n: PNode): PNode = var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar}) case t.kind of tyRef, tyPtr: n.typ = t.sons[0] - else: GlobalError(n.sons[0].info, errCircumNeedsPointer) - result = n + else: result = nil + #GlobalError(n.sons[0].info, errCircumNeedsPointer) proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode = - ## returns nil if not a built-in subscript operator; + ## returns nil if not a built-in subscript operator; also called for the + ## checking of assignments if sonsLen(n) == 1: var x = semDeref(c, n) + if x == nil: return nil result = newNodeIT(nkDerefExpr, x.info, x.typ) result.add(x[0]) return diff --git a/tests/accept/run/tgenericassign.nim b/tests/accept/run/tgenericassign.nim new file mode 100644 index 000000000..654b0ab8f --- /dev/null +++ b/tests/accept/run/tgenericassign.nim @@ -0,0 +1,24 @@ +discard """ + output: '''came here''' +""" + +type + TAny* = object {.pure.} + value*: pointer + rawType: pointer + +proc newAny(value, rawType: pointer): TAny = + result.value = value + result.rawType = rawType + +var name: cstring = "example" + +var ret: seq[tuple[name: string, a: TAny]] = @[] +for i in 0..8000: + var tup = ($name, newAny(nil, nil)) + assert(tup[0] == "example") + ret.add(tup) + assert(ret[ret.len()-1][0] == "example") + +echo "came here" + |