Skip to content

ForwardTrailingClosures is not source compatible with calls to View.sheet(isPresented:onDismiss:content:) #65921

@jqsilver

Description

@jqsilver

Description
The Swift proposal "Forward-scan matching for trailing closures" explicitly states that its implementation includes a heuristic that will allow for calls to SwiftUI's View.sheet method to continue to compile.

For the View.sheet(isPresented:onDismiss:content:) API, this means that onDismiss, which has a default argument, will be skipped in the forward match so that the unlabeled trailing closure will match content:, allowing this code to continue to compile correctly.

However, when I enable ForwardTrailingClosures in Swift 5.8, the example call does not continue to compile correctly.

Steps to reproduce
Using Xcode 14.3, I've created a new iOS App project with SwiftUI. ForwardScanCompatibilityRepro.zip
I modified the ContentView to look like this:

import SwiftUI

struct ContentView: View {
  @State private var isShowingSheet = false

  var body: some View {
    VStack {
      showButton
        .sheet(isPresented: $isShowingSheet) {
          Text("Hello")
        }
    }.padding()
  }

  var showButton: some View {
    Button("Show Sheet") {
      isShowingSheet.toggle()
    }
  }
}

This code compiles and runs just fine, but when I add -enable-upcoming-feature ForwardTrailingClosures to "Other Swift Flags" it no longer compiles. The error message states Missing argument for parameter 'content' in call.

If you modify the call to include the content: parameter then the code compiles.

        .sheet(isPresented: $isShowingSheet, content: {
          Text("Hello")
        })

Expected behavior

sheet(isPresented: $isPresented) { Text("Hello") } should compile with Swift 5.8 and -enable-upcoming-feature ForwardTrailingClosures.

Environment

  • Swift version info swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
    Target: arm64-apple-macosx13.0
  • Xcode version info Xcode 14.3 Build version 14E222b
  • Deployment target: iOS 16.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.call expressionsFeature → expressions: Call expressionsclosuresFeature: closurescompilerThe Swift compiler itselfsource compatibilityswift 5.9trailing closuresFeature: trailing closurestype checkerArea → compiler: Semantic analysistype inferenceFeature: type inferenceunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions