mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-07 04:14:19 +00:00
fix #20148 implicit compile time conversion int to ranged float causes compiler fatal error
(cherry picked from commit a51ed90c5d)
This commit is contained in:
@@ -450,9 +450,12 @@ proc opConv(c: PCtx; dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType):
|
||||
else: int(src.intVal != 0)
|
||||
of tyFloat..tyFloat64:
|
||||
dest.ensureKind(rkFloat)
|
||||
case skipTypes(srctyp, abstractRange).kind
|
||||
let srcKind = skipTypes(srctyp, abstractRange).kind
|
||||
case srcKind
|
||||
of tyInt..tyInt64, tyUInt..tyUInt64, tyEnum, tyBool, tyChar:
|
||||
dest.floatVal = toBiggestFloat(src.intVal)
|
||||
elif src.kind == rkInt:
|
||||
dest.floatVal = toBiggestFloat(src.intVal)
|
||||
else:
|
||||
dest.floatVal = src.floatVal
|
||||
of tyObject:
|
||||
|
||||
8
tests/statictypes/t20148.nim
Normal file
8
tests/statictypes/t20148.nim
Normal file
@@ -0,0 +1,8 @@
|
||||
type Percent = range[0.0 .. 1.0]
|
||||
# type Percent = float # using unlimited `float` works fine
|
||||
|
||||
proc initColor*(alpha: Percent): bool =
|
||||
echo alpha
|
||||
|
||||
const moduleInstanceStyle = initColor(1)
|
||||
# let moduleInstanceStyle = initColor(1) # using runtime conversion works fine
|
||||
Reference in New Issue
Block a user