low/high for float ranges (#11177)

This commit is contained in:
Oscar Nihlgård 2019-05-06 21:19:40 +02:00 • committed by Andreas Rumpf
commit 4c6fc173b7
4 changed files with 27 additions and 7 deletions

View file

@ -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: