fix range.getType crash
This commit is contained in:
parent
5a03eea518
commit
40c5175145
2 changed files with 13 additions and 7 deletions
|
|
@ -242,7 +242,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||||
of tyRange:
|
of tyRange:
|
||||||
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
|
||||||
result.add atomicType("range", mRange)
|
result.add atomicType("range", mRange)
|
||||||
if inst:
|
if inst and t.n.len == 2:
|
||||||
let rng = newNodeX(nkInfix)
|
let rng = newNodeX(nkInfix)
|
||||||
rng.add newIdentNode(getIdent(cache, ".."), info)
|
rng.add newIdentNode(getIdent(cache, ".."), info)
|
||||||
rng.add t.n.sons[0].copyTree
|
rng.add t.n.sons[0].copyTree
|
||||||
|
|
@ -250,7 +250,8 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||||
result.add rng
|
result.add rng
|
||||||
else:
|
else:
|
||||||
result.add t.n.sons[0].copyTree
|
result.add t.n.sons[0].copyTree
|
||||||
result.add t.n.sons[1].copyTree
|
if t.n.len > 1:
|
||||||
|
result.add t.n.sons[1].copyTree
|
||||||
of tyPointer: result = atomicType("pointer", mPointer)
|
of tyPointer: result = atomicType("pointer", mPointer)
|
||||||
of tyString: result = atomicType("string", mString)
|
of tyString: result = atomicType("string", mString)
|
||||||
of tyCString: result = atomicType("cstring", mCstring)
|
of tyCString: result = atomicType("cstring", mCstring)
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,14 @@ discard """
|
||||||
void; ntyVoid; void; void
|
void; ntyVoid; void; void
|
||||||
int; ntyInt; int; int
|
int; ntyInt; int; int
|
||||||
proc (); ntyProc; proc[void]; proc ()
|
proc (); ntyProc; proc[void]; proc ()
|
||||||
voidProc; ntyProc; proc[void]; proc ()'''
|
voidProc; ntyProc; proc[void]; proc ()
|
||||||
|
typeDesc[range[1 .. 5]]; ntyTypeDesc; typeDesc[range[1, 5]]; typeDesc[range[1 .. 5]]
|
||||||
|
typeDesc[range]; ntyTypeDesc; typeDesc[range[T]]; typeDesc[range]'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import macros
|
import macros
|
||||||
|
|
||||||
macro checkType(ex: typed; expected: string): untyped =
|
macro checkType(ex: typed): untyped =
|
||||||
echo ex.getTypeInst.repr, "; ", ex.typeKind, "; ", ex.getType.repr, "; ", ex.getTypeImpl.repr
|
echo ex.getTypeInst.repr, "; ", ex.typeKind, "; ", ex.getType.repr, "; ", ex.getTypeImpl.repr
|
||||||
|
|
||||||
macro checkProcType(fn: typed): untyped =
|
macro checkProcType(fn: typed): untyped =
|
||||||
|
|
@ -19,9 +21,9 @@ macro checkProcType(fn: typed): untyped =
|
||||||
proc voidProc = echo "hello"
|
proc voidProc = echo "hello"
|
||||||
proc intProc(a: int, b: float): int {.checkProcType.} = 10
|
proc intProc(a: int, b: float): int {.checkProcType.} = 10
|
||||||
|
|
||||||
checkType(voidProc(), "void")
|
checkType(voidProc())
|
||||||
checkType(intProc(10, 20.0), "int")
|
checkType(intProc(10, 20.0))
|
||||||
checkType(voidProc, "procTy")
|
checkType(voidProc)
|
||||||
checkProcType(voidProc)
|
checkProcType(voidProc)
|
||||||
|
|
||||||
# bug #10548
|
# bug #10548
|
||||||
|
|
@ -68,3 +70,6 @@ macro foobar(arg: typed): untyped =
|
||||||
var x: Vec2f
|
var x: Vec2f
|
||||||
|
|
||||||
foobar(x)
|
foobar(x)
|
||||||
|
|
||||||
|
checkType(range[1..5])
|
||||||
|
checkType(range)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue