Merge pull request #9085 from LemonBoy/fix-9079
Constant folding should not drop distinct types
This commit is contained in:
commit
959e3a08b1
2 changed files with 20 additions and 4 deletions
|
|
@ -37,10 +37,7 @@ proc newIntNodeT*(intVal: BiggestInt, n: PNode; g: ModuleGraph): PNode =
|
||||||
|
|
||||||
proc newFloatNodeT*(floatVal: BiggestFloat, n: PNode; g: ModuleGraph): PNode =
|
proc newFloatNodeT*(floatVal: BiggestFloat, n: PNode; g: ModuleGraph): PNode =
|
||||||
result = newFloatNode(nkFloatLit, floatVal)
|
result = newFloatNode(nkFloatLit, floatVal)
|
||||||
if skipTypes(n.typ, abstractVarRange).kind == tyFloat:
|
result.typ = n.typ
|
||||||
result.typ = getFloatLitType(g, result)
|
|
||||||
else:
|
|
||||||
result.typ = n.typ
|
|
||||||
result.info = n.info
|
result.info = n.info
|
||||||
|
|
||||||
proc newStrNodeT*(strVal: string, n: PNode; g: ModuleGraph): PNode =
|
proc newStrNodeT*(strVal: string, n: PNode; g: ModuleGraph): PNode =
|
||||||
|
|
|
||||||
19
tests/distinct/t9079.nim
Normal file
19
tests/distinct/t9079.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
25.0
|
||||||
|
210.0
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
Dollars = distinct float
|
||||||
|
|
||||||
|
proc `$`(d: Dollars): string {.borrow.}
|
||||||
|
proc `*` *(a, b: Dollars): Dollars {.borrow.}
|
||||||
|
proc `+` *(a, b: Dollars): Dollars {.borrow.}
|
||||||
|
|
||||||
|
var a = Dollars(20)
|
||||||
|
a = Dollars(25.0)
|
||||||
|
echo a
|
||||||
|
a = 10.Dollars * (20.Dollars + 1.Dollars)
|
||||||
|
echo a
|
||||||
Loading…
Add table
Add a link
Reference in a new issue