Bugfix: the size of an array may be a static tuple element
This commit is contained in:
parent
509d6e9232
commit
ab9969ed3b
2 changed files with 35 additions and 8 deletions
|
|
@ -301,7 +301,8 @@ proc semArrayIndex(c: PContext, n: PNode): PType =
|
||||||
localError(c.config, info, errOrdinalTypeExpected)
|
localError(c.config, info, errOrdinalTypeExpected)
|
||||||
result = makeRangeWithStaticExpr(c, e)
|
result = makeRangeWithStaticExpr(c, e)
|
||||||
if c.inGenericContext > 0: result.flags.incl tfUnresolved
|
if c.inGenericContext > 0: result.flags.incl tfUnresolved
|
||||||
elif e.kind in nkCallKinds and hasGenericArguments(e):
|
elif e.kind in (nkCallKinds + {nkBracketExpr}) and
|
||||||
|
hasGenericArguments(e):
|
||||||
if not isOrdinalType(e.typ):
|
if not isOrdinalType(e.typ):
|
||||||
localError(c.config, n[1].info, errOrdinalTypeExpected)
|
localError(c.config, n[1].info, errOrdinalTypeExpected)
|
||||||
# This is an int returning call, depending on an
|
# This is an int returning call, depending on an
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,39 @@ staticAlialProc instantiated with 6
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
proc plus(a, b: int): int = a + b
|
||||||
|
|
||||||
|
when true:
|
||||||
type
|
type
|
||||||
StaticTypeAlias = static[int]
|
StaticTypeAlias = static[int]
|
||||||
|
|
||||||
proc staticAliasProc(s: StaticTypeAlias) =
|
proc staticAliasProc(s: StaticTypeAlias) =
|
||||||
static: echo "staticAlialProc instantiated with ", s + 1
|
static: echo "staticAlialProc instantiated with ", s + 1
|
||||||
|
echo s
|
||||||
|
|
||||||
staticAliasProc 1+2
|
staticAliasProc 1+2
|
||||||
staticAliasProc 3
|
staticAliasProc 3
|
||||||
staticAliasProc 5
|
staticAliasProc 5
|
||||||
|
|
||||||
|
when true:
|
||||||
|
type
|
||||||
|
ArrayWrapper1[S: static int] = object
|
||||||
|
data: array[S + 1, int]
|
||||||
|
|
||||||
|
ArrayWrapper2[S: static[int]] = object
|
||||||
|
data: array[S.plus(2), int]
|
||||||
|
|
||||||
|
ArrayWrapper3[S: static[(int, string)]] = object
|
||||||
|
data: array[S[0], int]
|
||||||
|
|
||||||
|
var aw1: ArrayWrapper1[5]
|
||||||
|
var aw2: ArrayWrapper2[5]
|
||||||
|
var aw3: ArrayWrapper3[(10, "str")]
|
||||||
|
|
||||||
|
static:
|
||||||
|
assert aw1.data.high == 5
|
||||||
|
assert aw2.data.high == 6
|
||||||
|
assert aw3.data.high == 9
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue