diff options
author | Oscar NihlgÄrd <oscarnihlgard@gmail.com> | 2019-05-06 21:19:40 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-05-06 21:19:40 +0200 |
commit | 4c6fc173b772a4c93d82e9d544a0d5a1fe270eea (patch) | |
tree | eb98ab71d1b450746e695236b40ed5e3241e92f2 /compiler | |
parent | b1091f85d4d363f4368b65c54b898e83bec459e1 (diff) | |
download | Nim-4c6fc173b772a4c93d82e9d544a0d5a1fe270eea.tar.gz |
low/high for float ranges (#11177)
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semexprs.nim | 2 | ||||
-rw-r--r-- | compiler/semfold.nim | 10 |
2 files changed, 9 insertions, 3 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index cb52724b9..2cdc36c52 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -316,7 +316,7 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode = n.typ = getSysType(c.graph, n.info, tyInt) of tyArray: n.typ = typ.sons[0] # indextype - of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt8, tyUInt16, tyUInt32: + of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt8, tyUInt16, tyUInt32, tyFloat..tyFloat64: # do not skip the range! n.typ = n.sons[1].typ.skipTypes(abstractVar) of tyGenericParam: diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 5fb2fcd65..67ba736f8 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -617,11 +617,17 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = # If it has no sideEffect, it should be evaluated. But not here. return of mLow: - result = newIntNodeT(firstOrd(g.config, n.sons[1].typ), n, g) + if skipTypes(n.sons[1].typ, abstractVarRange).kind in tyFloat..tyFloat64: + result = newFloatNodeT(firstFloat(n.sons[1].typ), n, g) + else: + result = newIntNodeT(firstOrd(g.config, n.sons[1].typ), n, g) of mHigh: if skipTypes(n.sons[1].typ, abstractVar+{tyUserTypeClassInst}).kind notin {tySequence, tyString, tyCString, tyOpenArray, tyVarargs}: - result = newIntNodeT(lastOrd(g.config, skipTypes(n[1].typ, abstractVar)), n, g) + if skipTypes(n.sons[1].typ, abstractVarRange).kind in tyFloat..tyFloat64: + result = newFloatNodeT(lastFloat(n.sons[1].typ), n, g) + else: + result = newIntNodeT(lastOrd(g.config, skipTypes(n[1].typ, abstractVar)), n, g) else: var a = getArrayConstr(m, n.sons[1], g) if a.kind == nkBracket: |