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.
  • Loading branch information
metagn authored Sep 14, 2024
1 parent 61e04ba commit 6d362e0
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 @@ -423,7 +423,6 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P
if dstTyp.kind in {tyUInt..tyUInt64}:
result = newIntNodeT(maskBytes(val, int 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 @@ -52,3 +52,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 6d362e0

Please sign in to comment.