mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 13:30:33 +00:00
bugfix: UFCS for templates (ttempl3.nim enhanced)
This commit is contained in:
@@ -21,18 +21,19 @@ proc considerAcc*(n: PNode): PIdent =
|
||||
case n.len
|
||||
of 0: GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
||||
of 1: result = considerAcc(n.sons[0])
|
||||
of 2:
|
||||
if n[0].ident.id == ord(wStar):
|
||||
else:
|
||||
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)
|
||||
else:
|
||||
result = getIdent(n[0].ident.s & n[1].ident.s)
|
||||
else:
|
||||
var id = ""
|
||||
for i in 0.. <n.len:
|
||||
if n.sons[i].kind != nkIdent:
|
||||
GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
||||
id.add(n.sons[i].ident.s)
|
||||
result = getIdent(id)
|
||||
var id = ""
|
||||
for i in 0.. <n.len:
|
||||
let x = n.sons[i]
|
||||
case x.kind
|
||||
of nkIdent: id.add(x.ident.s)
|
||||
of nkSym: id.add(x.sym.name.s)
|
||||
else: GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
||||
result = getIdent(id)
|
||||
else:
|
||||
GlobalError(n.info, errIdentifierExpected, renderTree(n))
|
||||
|
||||
|
||||
@@ -40,3 +40,18 @@ template typedef(name: expr, typ: typeDesc) {.immediate.} =
|
||||
typedef(myint, int)
|
||||
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
|
||||
- make exceptions compatible with C++ exceptions
|
||||
- change how comments are part of the AST
|
||||
- find a better solution for gensym instead of `*ident`
|
||||
- extract nimdoc properly and document it finally
|
||||
- rethink the syntax: distinction between expr and stmt is unfortunate;
|
||||
indentation handling is quite complex too; problem with exception handling
|
||||
|
||||
Reference in New Issue
Block a user