Fix range type construction in the VM (#9205)
The `range[X,Y]` representation is wrong, we use `range[X .. Y]` instead. Fixes #9194
This commit is contained in:
parent
dad290accb
commit
8a1055adce
2 changed files with 29 additions and 2 deletions
|
|
@ -237,6 +237,13 @@ 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:
|
||||||
|
let rng = newNodeX(nkInfix)
|
||||||
|
rng.add newIdentNode(getIdent(cache, ".."), info)
|
||||||
|
rng.add t.n.sons[0].copyTree
|
||||||
|
rng.add t.n.sons[1].copyTree
|
||||||
|
result.add rng
|
||||||
|
else:
|
||||||
result.add t.n.sons[0].copyTree
|
result.add t.n.sons[0].copyTree
|
||||||
result.add t.n.sons[1].copyTree
|
result.add t.n.sons[1].copyTree
|
||||||
of tyPointer: result = atomicType("pointer", mPointer)
|
of tyPointer: result = atomicType("pointer", mPointer)
|
||||||
|
|
|
||||||
20
tests/macros/t9194.nim
Normal file
20
tests/macros/t9194.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
range[0 .. 100]
|
||||||
|
array[0 .. 100, int]
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo1 = range[0 .. 100]
|
||||||
|
Foo2 = array[0 .. 100, int]
|
||||||
|
|
||||||
|
macro get(T: typedesc): untyped =
|
||||||
|
# Get the X out of typedesc[X]
|
||||||
|
let tmp = getTypeImpl(T)
|
||||||
|
result = newStrLitNode(getTypeImpl(tmp[1]).repr)
|
||||||
|
|
||||||
|
echo Foo1.get
|
||||||
|
echo Foo2.get
|
||||||
Loading…
Add table
Add a link
Reference in a new issue