[SR-15971] Negative integer literal converted to generic unsigned integer type without warning #58232
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
expressions
Feature: expressions
generics
Feature: generic declarations and types
integer literals
Feature → literals: Integer literals
literals
Feature → expressions: Literals such as an integer or string literal
numerics
Area → standard library: Numeric API
standard library
Area: Standard library umbrella
swift 6.0
unexpected behavior
Bug: Unexpected behavior or incorrect output
Environment
Additional Detail from JIRA
md5: 13075866fbea31d75181d4790f9f8c31
Issue Description:
Reporting this after asking on forums.swift.org, where user @xwu suggested to report this as a bug:
In this simple piece of code, the integer literal
-1
is used where a value of typeT
is expected.T
conforms toFixedWidthInteger
so it's unknown at compile time whether the literal can be converted to the actual typeT
. IfT
is set to an unsigned integer type, the-1
simply becomes a0
:I would have expected a runtime error, or at least a warning at compile time, when comparing this to how integer literals are checked agains concrete types as compile time and how explicit casts using an integer type's initializer result in a runtime error in such a case.
The text was updated successfully, but these errors were encountered: