Make range checks in semConv (#7164)

* Remove NaN/Inf/NegInf magic
* Make range checks in semConv
* fix the failing line
* fix `firstOrd` and `lastOrd`
* fix `localError`
* remove debug comment
* Cleanup, fix failing test
* make tests green
This commit is contained in:
Oscar Nihlgård 2019-05-10 11:10:11 +02:00 • committed by Andreas Rumpf
commit de5c0d3aa9
9 changed files with 103 additions and 26 deletions

View file

@ -741,6 +741,22 @@ proc lastFloat*(t: PType): BiggestFloat =
internalError(newPartialConfigRef(), "invalid kind for lastFloat(" & $t.kind & ')')
NaN
proc floatRangeCheck*(x: BiggestFloat, t: PType): bool =
case t.kind
# This needs to be special cased since NaN is never
# part of firstFloat(t) .. lastFloat(t)
of tyFloat..tyFloat128:
true
of tyRange:
x in firstFloat(t) .. lastFloat(t)
of tyVar:
floatRangeCheck(x, t.sons[0])
of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tySink,
tyStatic, tyInferred, tyUserTypeClasses:
floatRangeCheck(x, lastSon(t))
else:
internalError(newPartialConfigRef(), "invalid kind for floatRangeCheck:" & $t.kind)
false
proc lengthOrd*(conf: ConfigRef; t: PType): BiggestInt =
case t.skipTypes(tyUserTypeClasses).kind