-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed as duplicate of#70323
Closed as duplicate of#70323
Copy link
Labels
SILaccepts invalidBug: Accepts invalidBug: Accepts invalidbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwaredefinite initializationArea → compiler → SIL: Definite initializationArea → compiler → SIL: Definite initializationmemory safetyFeature: memory safetyFeature: memory safetyscript modeFlag: Specific to script mode compilationFlag: Specific to script mode compilationswift 6.0
Description
Description
In Swift 5.4 and later, a variable can in some cases be used in the initial value of its own declaration. Doing so produces a crash at runtime rather than a compiler error.
Reproduction
let x: Any = x
Run in a Swift Playground in Xcode 15.0.1. Crashes at runtime with error:
error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0xfffffffffffffff8).
Expected behavior
Compiler error such as use of variable 'x' before its declaration
or variable used within its own initial value
.
The former is the compiler error given for do { let x: Any = x }
.
The latter is the error given by Swift 5.3.
Environment
The runtime error was produced in a Swift Playground in Xcode 15.0.1.
The lack of compiler error was reproduced in swiftc 5.9 and 5.4, but not in 5.3, using swift.godbolt.org.
Additional information
No response
Metadata
Metadata
Assignees
Labels
SILaccepts invalidBug: Accepts invalidBug: Accepts invalidbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwaredefinite initializationArea → compiler → SIL: Definite initializationArea → compiler → SIL: Definite initializationmemory safetyFeature: memory safetyFeature: memory safetyscript modeFlag: Specific to script mode compilationFlag: Specific to script mode compilationswift 6.0