This commit is contained in:
Andreas Rumpf
2020-04-19 10:01:04 +02:00
committed by GitHub
parent 4005f0d0e4
commit 9874981e75
4 changed files with 8 additions and 7 deletions

View File

@@ -1276,7 +1276,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
of tyNil: result = allowsNilDeprecated(c, f)
else: discard
of tyOrdinal:
if isOrdinalType(a):
if isOrdinalType(a, allowEnumWithHoles = optNimV1Emulation in c.c.config.globalOptions):
var x = if a.kind == tyOrdinal: a[0] else: a
if f[0].kind == tyNone:
result = isGeneric

View File

@@ -161,7 +161,7 @@ proc enumHasHoles*(t: PType): bool =
proc isOrdinalType*(t: PType, allowEnumWithHoles: bool = false): bool =
assert(t != nil)
const
baseKinds = {tyChar,tyInt..tyInt64,tyUInt..tyUInt64,tyBool,tyEnum}
baseKinds = {tyChar, tyInt..tyInt64, tyUInt..tyUInt64, tyBool, tyEnum}
parentKinds = {tyRange, tyOrdinal, tyGenericInst, tyAlias, tySink, tyDistinct}
result = (t.kind in baseKinds and (not t.enumHasHoles or allowEnumWithHoles)) or
(t.kind in parentKinds and isOrdinalType(t.lastSon, allowEnumWithHoles))

View File

@@ -9,6 +9,7 @@
#[
- introduce Phi nodes to complete the SSA representation
- the analysis has to take 'break', 'continue' and 'raises' into account
- We need to map arrays to Z3 and test for something like 'forall(i, (i in 3..4) -> (a[i] > 3))'
- We need teach DrNim what 'inc', 'dec' and 'swap' mean, for example

View File

@@ -24,7 +24,7 @@ iterator countdown*[T](a, b: T, step: Positive = 1): T {.inline.} =
yield res
if res == b: break
dec(res, step)
elif T is IntLikeForCount:
elif T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res >= int(b):
yield T(res)
@@ -52,7 +52,7 @@ when defined(nimNewRoof):
## for i in countup(2, 9, 3):
## echo i # => 2; 5; 8
mixin inc
when T is IntLikeForCount:
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
@@ -73,7 +73,7 @@ when defined(nimNewRoof):
## for i in 3 .. 7:
## echo i # => 3; 4; 5; 6; 7
mixin inc
when T is IntLikeForCount:
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
@@ -138,7 +138,7 @@ else: # not defined(nimNewRoof)
##
## for i in countup(2, 9, 3):
## echo i # => 2; 5; 8
when T is IntLikeForCount:
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
@@ -159,7 +159,7 @@ else: # not defined(nimNewRoof)
## for i in 3 .. 7:
## echo i # => 3; 4; 5; 6; 7
mixin inc
when T is IntLikeForCount:
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)