From e9b5a4e25dcf7929cbda9e67d1775d3ccda82c57 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 27 Sep 2018 17:08:01 +0200 Subject: [PATCH] Constant folding should not drop distinct types Fixes #9079 --- compiler/semfold.nim | 5 +---- tests/distinct/t9079.nim | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tests/distinct/t9079.nim diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 0018f07559..627877cbeb 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -37,10 +37,7 @@ proc newIntNodeT*(intVal: BiggestInt, n: PNode; g: ModuleGraph): PNode = proc newFloatNodeT*(floatVal: BiggestFloat, n: PNode; g: ModuleGraph): PNode = result = newFloatNode(nkFloatLit, floatVal) - if skipTypes(n.typ, abstractVarRange).kind == tyFloat: - result.typ = getFloatLitType(g, result) - else: - result.typ = n.typ + result.typ = n.typ result.info = n.info proc newStrNodeT*(strVal: string, n: PNode; g: ModuleGraph): PNode = diff --git a/tests/distinct/t9079.nim b/tests/distinct/t9079.nim new file mode 100644 index 0000000000..a891ef27de --- /dev/null +++ b/tests/distinct/t9079.nim @@ -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