6.0.3: Unrelated structs end up sharing a closure when they shouldn't #78922
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
Description
The code below defines a struct,
ClosureStorer
, that accepts a closure as an initialization argument. The classUsesStorers
creates two of these structs, one with<
as an argument and the other with>
. The problem is that both structs end up sharing a reference to the same closure.I suspect that the underlying issue lies somewhere in the domain of class initialization. If the line
is rewritten to
then the problem does not occur.
Other cases where the problem doesn't occur:
Reproduction
Run the following code:
As indicated in the comments, the two ClosureStorer structs return (or should return, if the issue is being demonstrated correctly) the same comparison results.
Xcode shows
ClosureStorer.op
as having the same address for both copies of the struct. The debug output labels this "implicit closure #1".Expected behavior
The two ClosureStorer structs are independent and should each return results that conform to the comparison operator they're initialized with. The correct output is "false true / true false", demonstrating that the closures return different results.
Environment
I'm seeing this problem on Xcode 16.2 (16C5032a), which I believe is Swift 6.0.3.
Additional information
No response
The text was updated successfully, but these errors were encountered: