mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
overloading of [] for derefence operation should be possible now
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user