Skip to content

Commit

Permalink
fix regression with uint constant losing abstract type (#24105)
Browse files Browse the repository at this point in the history
fixes #24104, refs #23955

The line `result.typ = dstTyp` added in #23955 changes the type of
`result`, which was the type of `n` due to the argument passed to
`newIntNodeT`, to the abstract type skipped `dstTyp`. The line is
removed to just keep the type as abstract.

(cherry picked from commit 6d362e0)
  • Loading branch information
metagn authored and narimiran committed Sep 16, 2024
1 parent 8bc8347 commit fd1d008
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 0 additions & 1 deletion compiler/semfold.nim
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P
if dstTyp.kind in {tyUInt..tyUInt64}:
result = newIntNodeT(maskBytes(val, getSize(g.config, dstTyp)), n, idgen, g)
result.transitionIntKind(nkUIntLit)
result.typ = dstTyp
else:
if check: rangeCheck(n, val, g)
result = newIntNodeT(val, n, idgen, g)
Expand Down
7 changes: 7 additions & 0 deletions tests/int/t1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ block: # bug #23954
doAssert testRT_u8 == 7
const testCT_u8 : uint8 = 0x107.uint8
doAssert testCT_u8 == 7

block: # issue #24104
type P = distinct uint # uint, uint8, uint16, uint32, uint64
let v = 0.P
case v
of 0.P: discard
else: discard

0 comments on commit fd1d008

Please sign in to comment.