Skip to content

Conversation

@kavon
Copy link
Member

@kavon kavon commented Jun 13, 2023

After polishing the diagnostics a bit, I got some of the closure ones wrong:

struct NonCopyableStruct: ~Copyable {}

var globFn: () -> () = {}
func forceEscaping(_ esc: @escaping () -> ()) {
  globFn = esc
}

func closureDiagnosticsSimple() {
  var s = NonCopyableStruct()
  let f = {
    _ = consume s  // error: missing reinitialization of inout parameter 's' after consume
    s = NonCopyableStruct()
  }
  forceEscaping(f)
  f()
}

There are a few problems here:

  1. This shouldn't be called an inout parameter and instead a closure capture.
  2. Seems it's not actually possible to reinit to remedy this situation, but only when the closure is escaping. When it is not escaping, it's valid to reconcile this with reinit. We are saying noncopyable '%0' cannot be consumed when captured by a closure when a non-reconcilable consume happens in a closure. So we should specify "an escaping closure" here.

rdar://109908383

@kavon
Copy link
Member Author

kavon commented Jun 13, 2023

@swift-ci smoke test and merge

@kavon kavon force-pushed the improve-noncopyable-closure-diags branch from 79d8bd5 to 219f94f Compare June 13, 2023 04:04
@kavon
Copy link
Member Author

kavon commented Jun 13, 2023

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit f79938c into swiftlang:main Jun 13, 2023
@kavon kavon deleted the improve-noncopyable-closure-diags branch June 13, 2023 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants