mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 21:43:33 +00:00
fixes #23177
`changeType` doesn't perform range checks to see if the expression fits
the new type [if the old type is the same as the new
type](62d8ca4306/compiler/semexprs.nim (L633)).
For `nkIntLit`, we previously set the type to the concrete base of the
expected type first, then call `changeType`, which works for things like
range types but not bare types of smaller bit size like `int8`. Now we
don't set the type (so the type is nil), and `changeType` performs the
range check when the type is unset (nil).
11 lines
115 B
Nim
11 lines
115 B
Nim
discard """
|
|
errormsg: "cannot convert 256 to int8"
|
|
line: 9
|
|
"""
|
|
|
|
# issue #23177
|
|
|
|
var x: int8
|
|
x = 256
|
|
echo x # 0
|