Merge pull request #4604 from mbaulch/fix3658

Fix #3658. Types derived from ordinals are ordinal. Code cleanup.
This commit is contained in:
Andreas Rumpf 2016-08-11 15:05:49 +02:00 • committed by GitHub
commit 40de07f63c
2 changed files with 12 additions and 6 deletions

View file

@ -114,8 +114,12 @@ proc semTypeTraits(c: PContext, n: PNode): PNode =
proc semOrd(c: PContext, n: PNode): PNode = proc semOrd(c: PContext, n: PNode): PNode =
result = n result = n
result.typ = makeRangeType(c, firstOrd(n.sons[1].typ), let parType = n.sons[1].typ
lastOrd(n.sons[1].typ), n.info) 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 = proc semBindSym(c: PContext, n: PNode): PNode =
result = copyNode(n) result = copyNode(n)

View file

@ -148,10 +148,12 @@ proc skipGeneric(t: PType): PType =
proc isOrdinalType(t: PType): bool = proc isOrdinalType(t: PType): bool =
assert(t != nil) assert(t != nil)
# caution: uint, uint64 are no ordinal types! const
result = t.kind in {tyChar,tyInt..tyInt64,tyUInt8..tyUInt32,tyBool,tyEnum} or # caution: uint, uint64 are no ordinal types!
(t.kind in {tyRange, tyOrdinal, tyConst, tyMutable, tyGenericInst}) and baseKinds = {tyChar,tyInt..tyInt64,tyUInt8..tyUInt32,tyBool,tyEnum}
isOrdinalType(t.sons[0]) 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 = proc enumHasHoles(t: PType): bool =
var b = t var b = t