Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad diagnostic when constructor can't initialize isolated property #74557

Open
NachoSoto opened this issue Jun 19, 2024 · 2 comments
Open

Bad diagnostic when constructor can't initialize isolated property #74557

NachoSoto opened this issue Jun 19, 2024 · 2 comments
Labels
actor isolation Feature → concurrency: Actor isolation bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features declarations Feature: declarations definite initialization Area → compiler → SIL: Definite initialization diagnostics QoI Bug: Diagnostics Quality of Implementation init Feature → declarations: Initializers SIL swift 6.0

Comments

@NachoSoto
Copy link
Contributor

Description

The following code is not correct, but the diagnostic it produces is very misleading.

Reproduction

public final class Data {
  // Return from initializer without initializing all stored properties
  init() { }

  @MainActor
  private let n: Int = f()
}

@MainActor
func f() -> Int { 0 }

Expected behavior

The diagnostic should mention that the non-isolated init can't invoke the @MainActor isolated f.

Environment

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0

Additional information

No response

@NachoSoto NachoSoto added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jun 19, 2024
@AnthonyLatsis AnthonyLatsis added concurrency Feature: umbrella label for concurrency language features compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation definite initialization Area → compiler → SIL: Definite initialization SIL actor isolation Feature → concurrency: Actor isolation init Feature → declarations: Initializers declarations Feature: declarations swift 6.0 and removed triage needed This issue needs more specific labels labels Jun 19, 2024
@gottesmm
Copy link
Contributor

@NachoSoto next time, can you please put the actual output from the compiler. Makes it easier to see exactly what is going on. That way we have something like this that shows where the source loc is/etc:

%   ./bin/swift-frontend test.swift -swift-version 6 -c                
test.swift:3:12: error: return from initializer without initializing all stored properties
 1 | public final class Data {
 2 |   // Return from initializer without initializing all stored properties
 3 |   init() { }
   |            `- error: return from initializer without initializing all stored properties
 4 | 
 5 |   @MainActor
 6 |   private let n: Int = f()
   |               `- note: 'self.n' not initialized
 7 | }
 8 | 

That being said... thank you for the test case! = ).

@NachoSoto
Copy link
Contributor Author

Good to know, will do that moving forward!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actor isolation Feature → concurrency: Actor isolation bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features declarations Feature: declarations definite initialization Area → compiler → SIL: Definite initialization diagnostics QoI Bug: Diagnostics Quality of Implementation init Feature → declarations: Initializers SIL swift 6.0
Projects
None yet
Development

No branches or pull requests

3 participants