- Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
(i tried reproducing this outside of SwiftUI, but was unable to. the example below is the smallest i managed to reduce this issue.)
the compiler is unable to compile the program below, failing in the onChange closure.
i have no idea what is causing this, but either of the following changes makes it compile fine:
- making
S1non-generic; - making the
TinS1.initnon-optional; - making
S1.initnon-generic and changing the 1st param's type toInt?; - simplifying the expression passed to
S1's initializer to a non-ternary; - extracting the
Taskcreation into a separate instance method, and calling that from theonChangeclosure
Reproduction
import SwiftUI struct S1<A: View>: View { var body: some View { EmptyView() } init<T>( _: T?, @ViewBuilder _: () -> A = { EmptyView() } ) {} } struct S2: View { let x: Int var body: some View { S1(true ? x : nil) .onChange(of: x) { _, _ in Task {} // Ambiguous use of 'init(name:priority:operation:)' } } }Expected behavior
it should work
Environment
swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx15.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels