diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2018-06-30 13:43:55 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-06-30 13:43:55 +0200 |
commit | eec239e851c6be4922d9746d07a20c37c0157442 (patch) | |
tree | 133325ad0b862035a44aaab30752d5f3d0571297 /compiler | |
parent | 7ae9c4358e9385bbcce0b1acd874e3e2a51a1613 (diff) | |
download | Nim-eec239e851c6be4922d9746d07a20c37c0157442.tar.gz |
Fix constant folding of len() with concept type (#8143)
Fixes #7952
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/types.nim | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/types.nim b/compiler/types.nim index c5af855cc..4d3f99c31 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -623,7 +623,7 @@ proc firstOrd*(conf: ConfigRef; t: PType): BiggestInt = assert(t.n.sons[0].kind == nkSym) result = t.n.sons[0].sym.position of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tySink, - tyStatic, tyInferred, tyUserTypeClassInst: + tyStatic, tyInferred, tyUserTypeClasses: result = firstOrd(conf, lastSon(t)) of tyOrdinal: if t.len > 0: result = firstOrd(conf, lastSon(t)) @@ -642,7 +642,7 @@ proc firstFloat*(t: PType): BiggestFloat = getFloatValue(t.n.sons[0]) of tyVar: firstFloat(t.sons[0]) of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tySink, - tyStatic, tyInferred: + tyStatic, tyInferred, tyUserTypeClasses: firstFloat(lastSon(t)) else: internalError(newPartialConfigRef(), "invalid kind for firstFloat(" & $t.kind & ')') @@ -679,7 +679,7 @@ proc lastOrd*(conf: ConfigRef; t: PType; fixedUnsigned = false): BiggestInt = assert(t.n.sons[sonsLen(t.n) - 1].kind == nkSym) result = t.n.sons[sonsLen(t.n) - 1].sym.position of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tySink, - tyStatic, tyInferred: + tyStatic, tyInferred, tyUserTypeClasses: result = lastOrd(conf, lastSon(t)) of tyProxy: result = 0 of tyOrdinal: @@ -699,7 +699,7 @@ proc lastFloat*(t: PType): BiggestFloat = assert(t.n.kind == nkRange) getFloatValue(t.n.sons[1]) of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tySink, - tyStatic, tyInferred: + tyStatic, tyInferred, tyUserTypeClasses: lastFloat(lastSon(t)) else: internalError(newPartialConfigRef(), "invalid kind for lastFloat(" & $t.kind & ')') @@ -707,7 +707,7 @@ proc lastFloat*(t: PType): BiggestFloat = proc lengthOrd*(conf: ConfigRef; t: PType): BiggestInt = - case t.kind + case t.skipTypes(tyUserTypeClasses).kind of tyInt64, tyInt32, tyInt: result = lastOrd(conf, t) of tyDistinct: result = lengthOrd(conf, t.sons[0]) else: @@ -717,7 +717,7 @@ proc lengthOrd*(conf: ConfigRef; t: PType): BiggestInt = if last == high(BiggestInt) and first <= 0: result = last else: - result = lastOrd(conf, t) - firstOrd(conf, t) + 1 + result = last - first + 1 # -------------- type equality ----------------------------------------------- |