bugfix: UFCS for templates (ttempl3.nim enhanced)
This commit is contained in:
parent
7a249eb8c1
commit
bb7a14fec0
3 changed files with 27 additions and 10 deletions
|
|
@ -21,18 +21,19 @@ proc considerAcc*(n: PNode): PIdent =
|
||||||
case n.len
|
case n.len
|
||||||
of 0: GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
of 0: GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
||||||
of 1: result = considerAcc(n.sons[0])
|
of 1: result = considerAcc(n.sons[0])
|
||||||
of 2:
|
else:
|
||||||
if n[0].ident.id == ord(wStar):
|
if n.len == 2 and n[0].kind == nkIdent and n[0].ident.id == ord(wStar):
|
||||||
|
# XXX find a better way instead of `*x` for 'genSym'
|
||||||
result = genSym(n[1].ident.s)
|
result = genSym(n[1].ident.s)
|
||||||
else:
|
else:
|
||||||
result = getIdent(n[0].ident.s & n[1].ident.s)
|
var id = ""
|
||||||
else:
|
for i in 0.. <n.len:
|
||||||
var id = ""
|
let x = n.sons[i]
|
||||||
for i in 0.. <n.len:
|
case x.kind
|
||||||
if n.sons[i].kind != nkIdent:
|
of nkIdent: id.add(x.ident.s)
|
||||||
GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
of nkSym: id.add(x.sym.name.s)
|
||||||
id.add(n.sons[i].ident.s)
|
else: GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
||||||
result = getIdent(id)
|
result = getIdent(id)
|
||||||
else:
|
else:
|
||||||
GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,3 +40,18 @@ template typedef(name: expr, typ: typeDesc) {.immediate.} =
|
||||||
typedef(myint, int)
|
typedef(myint, int)
|
||||||
var x: PMyInt
|
var x: PMyInt
|
||||||
|
|
||||||
|
|
||||||
|
# Test UFCS
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo = object
|
||||||
|
arg: int
|
||||||
|
|
||||||
|
proc initFoo(arg: int): Foo =
|
||||||
|
result.arg = arg
|
||||||
|
|
||||||
|
template create(typ: typeDesc, arg: expr): expr = `init typ`(arg)
|
||||||
|
|
||||||
|
var ff = Foo.create(12)
|
||||||
|
|
||||||
|
echo ff.arg
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -23,6 +23,7 @@ version 0.9.0
|
||||||
- we need to support iteration of 2 different data structures in parallel
|
- we need to support iteration of 2 different data structures in parallel
|
||||||
- make exceptions compatible with C++ exceptions
|
- make exceptions compatible with C++ exceptions
|
||||||
- change how comments are part of the AST
|
- change how comments are part of the AST
|
||||||
|
- find a better solution for gensym instead of `*ident`
|
||||||
- extract nimdoc properly and document it finally
|
- extract nimdoc properly and document it finally
|
||||||
- rethink the syntax: distinction between expr and stmt is unfortunate;
|
- rethink the syntax: distinction between expr and stmt is unfortunate;
|
||||||
indentation handling is quite complex too; problem with exception handling
|
indentation handling is quite complex too; problem with exception handling
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue