Skip to content

Commit 959e3a0

Browse files
authored
Merge pull request #9085 from LemonBoy/fix-9079
Constant folding should not drop distinct types
2 parents baccd1a + e9b5a4e commit 959e3a0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

compiler/semfold.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ proc newIntNodeT*(intVal: BiggestInt, n: PNode; g: ModuleGraph): PNode =
3737

3838
proc newFloatNodeT*(floatVal: BiggestFloat, n: PNode; g: ModuleGraph): PNode =
3939
result = newFloatNode(nkFloatLit, floatVal)
40-
if skipTypes(n.typ, abstractVarRange).kind == tyFloat:
41-
result.typ = getFloatLitType(g, result)
42-
else:
43-
result.typ = n.typ
40+
result.typ = n.typ
4441
result.info = n.info
4542

4643
proc newStrNodeT*(strVal: string, n: PNode; g: ModuleGraph): PNode =

tests/distinct/t9079.nim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
discard """
2+
output: '''
3+
25.0
4+
210.0
5+
'''
6+
"""
7+
8+
type
9+
Dollars = distinct float
10+
11+
proc `$`(d: Dollars): string {.borrow.}
12+
proc `*` *(a, b: Dollars): Dollars {.borrow.}
13+
proc `+` *(a, b: Dollars): Dollars {.borrow.}
14+
15+
var a = Dollars(20)
16+
a = Dollars(25.0)
17+
echo a
18+
a = 10.Dollars * (20.Dollars + 1.Dollars)
19+
echo a

0 commit comments

Comments
 (0)