fixes #1334
This commit is contained in:
parent
7ef076a04a
commit
ebe313e627
3 changed files with 40 additions and 13 deletions
|
|
@ -116,14 +116,6 @@ proc iiTablePut*(t: var TIITable, key, val: int)
|
||||||
|
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
proc skipConv*(n: PNode): PNode =
|
|
||||||
case n.kind
|
|
||||||
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
|
|
||||||
result = n.sons[0]
|
|
||||||
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
|
||||||
result = n.sons[1]
|
|
||||||
else: result = n
|
|
||||||
|
|
||||||
proc skipConvAndClosure*(n: PNode): PNode =
|
proc skipConvAndClosure*(n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
while true:
|
while true:
|
||||||
|
|
@ -135,10 +127,6 @@ proc skipConvAndClosure*(n: PNode): PNode =
|
||||||
result = result.sons[1]
|
result = result.sons[1]
|
||||||
else: break
|
else: break
|
||||||
|
|
||||||
proc skipConvTakeType*(n: PNode): PNode =
|
|
||||||
result = n.skipConv
|
|
||||||
result.typ = n.typ
|
|
||||||
|
|
||||||
proc sameValue*(a, b: PNode): bool =
|
proc sameValue*(a, b: PNode): bool =
|
||||||
result = false
|
result = false
|
||||||
case a.kind
|
case a.kind
|
||||||
|
|
|
||||||
|
|
@ -1369,3 +1369,35 @@ proc containsCompileTimeOnly*(t: PType): bool =
|
||||||
if t.sons[i] != nil and isCompileTimeOnly(t.sons[i]):
|
if t.sons[i] != nil and isCompileTimeOnly(t.sons[i]):
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
type
|
||||||
|
OrdinalType* = enum
|
||||||
|
NoneLike, IntLike, FloatLike
|
||||||
|
|
||||||
|
proc classify*(t: PType): OrdinalType =
|
||||||
|
## for convenient type checking:
|
||||||
|
if t == nil:
|
||||||
|
result = NoneLike
|
||||||
|
else:
|
||||||
|
case skipTypes(t, abstractVarRange).kind
|
||||||
|
of tyFloat..tyFloat128: result = FloatLike
|
||||||
|
of tyInt..tyInt64, tyUInt..tyUInt64, tyBool, tyChar, tyEnum:
|
||||||
|
result = IntLike
|
||||||
|
else: result = NoneLike
|
||||||
|
|
||||||
|
proc skipConv*(n: PNode): PNode =
|
||||||
|
result = n
|
||||||
|
case n.kind
|
||||||
|
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
|
||||||
|
# only skip the conversion if it doesn't lose too important information
|
||||||
|
# (see bug #
|
||||||
|
if n.sons[0].typ.classify == n.typ.classify:
|
||||||
|
result = n.sons[0]
|
||||||
|
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
||||||
|
if n.sons[1].typ.classify == n.typ.classify:
|
||||||
|
result = n.sons[1]
|
||||||
|
else: discard
|
||||||
|
|
||||||
|
proc skipConvTakeType*(n: PNode): PNode =
|
||||||
|
result = n.skipConv
|
||||||
|
result.typ = n.typ
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ discard """
|
||||||
output: '''1
|
output: '''1
|
||||||
0
|
0
|
||||||
Whopie
|
Whopie
|
||||||
12'''
|
12
|
||||||
|
1.7'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
echo len([1_000_000]) #OUT 1
|
echo len([1_000_000]) #OUT 1
|
||||||
|
|
@ -39,3 +40,9 @@ var val12 = TSomeRange(hour: 12)
|
||||||
|
|
||||||
value = $(if val12.hour > 12: val12.hour - 12 else: val12.hour)
|
value = $(if val12.hour > 12: val12.hour - 12 else: val12.hour)
|
||||||
echo value
|
echo value
|
||||||
|
|
||||||
|
# bug #1334
|
||||||
|
|
||||||
|
var ys = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2]
|
||||||
|
#var x = int(ys.high / 2) #echo ys[x] # Works
|
||||||
|
echo ys[int(ys.high / 2)] # Doesn't work
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue