Opaque types as inferred associated types violate type safety #73245
Labels
accepts invalid
Bug: Accepts invalid
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
opaque result types
Feature → types → opaque types: opaque result types
opaque types
Feature → types: opaque types
swift 6.0
type checker
Area → compiler: Semantic analysis
Description / Reproduction
The following ought to generate a type-error where
whoops
is declared, but instead it complies and violates type safety, interpreting memory as incorrect type.In the example above, the
String
"hi"
was reinterpreted as anInt
sinceExampleFactor.Example
isInt
.If we were to
unsafeBitCast
aString
toInt
, it would trap since the sizes don't match. Instead, we can run the following:As you can see, the first component matches the value of
whoops
, confirming that Swift in the first example silently reinterpretedwhoops
's initializing value as a conflicting type.Expected behavior
Environment
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered: