diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-08-11 15:05:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-11 15:05:49 +0200 |
commit | 40de07f63c43622a510d66caabf2f3b45419e627 (patch) | |
tree | 5a6bd191af0f2a085a525becac332907fc2da187 | |
parent | dd84dc85d067f0936746b8a80e7f249611b68da2 (diff) | |
parent | 674a1110f0ad8b95bb6d7332c87aa1c684cd0973 (diff) | |
download | Nim-40de07f63c43622a510d66caabf2f3b45419e627.tar.gz |
Merge pull request #4604 from mbaulch/fix3658
Fix #3658. Types derived from ordinals are ordinal. Code cleanup.
-rw-r--r-- | compiler/semmagic.nim | 8 | ||||
-rw-r--r-- | compiler/types.nim | 10 |
2 files changed, 12 insertions, 6 deletions
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index d9fec6275..cbe9bc176 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -114,8 +114,12 @@ proc semTypeTraits(c: PContext, n: PNode): PNode = proc semOrd(c: PContext, n: PNode): PNode = result = n - result.typ = makeRangeType(c, firstOrd(n.sons[1].typ), - lastOrd(n.sons[1].typ), n.info) + let parType = n.sons[1].typ + if isOrdinalType(parType) or parType.kind == tySet: + result.typ = makeRangeType(c, firstOrd(parType), lastOrd(parType), n.info) + else: + localError(n.info, errOrdinalTypeExpected) + result.typ = errorType(c) proc semBindSym(c: PContext, n: PNode): PNode = result = copyNode(n) diff --git a/compiler/types.nim b/compiler/types.nim index c56382b89..ff60730f0 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -148,10 +148,12 @@ proc skipGeneric(t: PType): PType = proc isOrdinalType(t: PType): bool = assert(t != nil) - # caution: uint, uint64 are no ordinal types! - result = t.kind in {tyChar,tyInt..tyInt64,tyUInt8..tyUInt32,tyBool,tyEnum} or - (t.kind in {tyRange, tyOrdinal, tyConst, tyMutable, tyGenericInst}) and - isOrdinalType(t.sons[0]) + const + # caution: uint, uint64 are no ordinal types! + baseKinds = {tyChar,tyInt..tyInt64,tyUInt8..tyUInt32,tyBool,tyEnum} + parentKinds = {tyRange, tyOrdinal, tyConst, tyMutable, tyGenericInst, + tyDistinct} + t.kind in baseKinds or (t.kind in parentKinds and isOrdinalType(t.sons[0])) proc enumHasHoles(t: PType): bool = var b = t |