Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semfold: fix range-check folding #822

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/sem/semfold.nim
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
let a = getConstExpr(m, n[0], idgen, g)
if a == nil: return
if leValueConv(n[1], a) and leValueConv(a, n[2]):
result = a # a <= x and x <= b
result.typ = n.typ
# a <= x and x <= b
result = foldConv(n, a, idgen, g, check=false)
else:
result = g.config.newError(n,
PAstDiag(kind: adSemInvalidRangeConversion))
Expand Down
9 changes: 9 additions & 0 deletions tests/lang_types/range/trange.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
discard """
targets: "c js vm"
output: '''
TSubRange: 5 from 1 to 10
#FF3722
Expand Down Expand Up @@ -154,3 +155,11 @@ block:
c = d
doAssert a == b
doAssert c == d

block int_literal_to_float_range:
type Range = range[0'f..1'f]

var val = 0'f
# use the value in a comparison in order to make sure that
# the conversion really worked
doAssert val == Range(0)