Unexpected Behavior in Swift 5.9 with ~Copyable
and consuming
in For Loop
#68230
Labels
accepts invalid
Bug: Accepts invalid
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
for-in loops
Feature: for-in loops
noncopyable struct/enum
Feature → declarations: Noncopyable value type declarations
struct
Feature → type declarations: Structure declarations
swift 5.9
Description
When using the
~Copyable
andconsuming
features of Swift 5.9 within afor
loop, the expected compile-time error is not produced.Instead, the code executes and results in unexpected deinitialization behavior.
Steps to reproduce
Here's the code sample:
Output:
Expected behavior
When using
~Copyable
andconsuming
within afor
loop, the compiler should generate a compile-time error.This error is not produced, leading to unnecessary calls to
deinit
. The lack of a compile-time error could lead to incorrect object creation and destruction.Environment
Additional information
main()
andrun()
functions and verified thatdeinit
is being called in both functions.The text was updated successfully, but these errors were encountered: