overloading of [] for derefence operation should be possible now
This commit is contained in:
parent
e5eb36e472
commit
958961bd8d
3 changed files with 31 additions and 5 deletions
|
|
@ -772,8 +772,8 @@ proc genEcho(p: BProc, n: PNode) =
|
||||||
for i in countup(1, n.len-1):
|
for i in countup(1, n.len-1):
|
||||||
initLocExpr(p, n.sons[i], a)
|
initLocExpr(p, n.sons[i], a)
|
||||||
appf(args, ", ($1)->data", [rdLoc(a)])
|
appf(args, ", ($1)->data", [rdLoc(a)])
|
||||||
appcg(p, cpsStmts, "printf(\"" & repeatStr(n.len-1, "%s") &
|
appcg(p, cpsStmts, "printf($1$2);$n", [
|
||||||
"\\n\"$1);$n", [args])
|
makeCString(repeatStr(n.len-1, "%s") & tnl), args])
|
||||||
|
|
||||||
proc genCall(p: BProc, t: PNode, d: var TLoc) =
|
proc genCall(p: BProc, t: PNode, d: var TLoc) =
|
||||||
var op, a: TLoc
|
var op, a: TLoc
|
||||||
|
|
|
||||||
|
|
@ -726,13 +726,15 @@ proc semDeref(c: PContext, n: PNode): PNode =
|
||||||
var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar})
|
var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar})
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyRef, tyPtr: n.typ = t.sons[0]
|
of tyRef, tyPtr: n.typ = t.sons[0]
|
||||||
else: GlobalError(n.sons[0].info, errCircumNeedsPointer)
|
else: result = nil
|
||||||
result = n
|
#GlobalError(n.sons[0].info, errCircumNeedsPointer)
|
||||||
|
|
||||||
proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
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:
|
if sonsLen(n) == 1:
|
||||||
var x = semDeref(c, n)
|
var x = semDeref(c, n)
|
||||||
|
if x == nil: return nil
|
||||||
result = newNodeIT(nkDerefExpr, x.info, x.typ)
|
result = newNodeIT(nkDerefExpr, x.info, x.typ)
|
||||||
result.add(x[0])
|
result.add(x[0])
|
||||||
return
|
return
|
||||||
|
|
|
||||||
24
tests/accept/run/tgenericassign.nim
Normal file
24
tests/accept/run/tgenericassign.nim
Normal file
|
|
@ -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"
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue