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

[SR-15916] @MainActor-isolated default arguments for @MainActor-isolated functions #58177

Closed
groue opened this issue Feb 26, 2022 · 8 comments · Fixed by #68794 or #70257
Closed

[SR-15916] @MainActor-isolated default arguments for @MainActor-isolated functions #58177

groue opened this issue Feb 26, 2022 · 8 comments · Fixed by #68794 or #70257
Assignees
Labels
actor isolation Feature → concurrency: Actor isolation actor Feature → concurrency: `actor` declarations 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 default arguments Feature: default arguments for value parameters type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@groue
Copy link

groue commented Feb 26, 2022

Previous ID SR-15916
Radar None
Original Reporter @groue
Type Bug
Environment

Xcode 13.3 beta 3 (13E5104i)

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 618b69843e92ff0edf9587c87894767b

Issue Description:

Hello,

The following snippet does not compile:

@MainActor class Foo { }

// error: call to main actor-isolated initializer 'init()' in a synchronous nonisolated context
// @MainActor func f(foo: Foo = Foo()) { }
//                               ^
// note: calls to initializer 'init()' from outside of its actor context are implicitly asynchronous
// @MainActor class Foo {
//                  ^
@MainActor func f(foo: Foo = Foo()) { }

It should compile, since everything in the declaration of the f function is MainActor-isolated.

@groue
Copy link
Author

groue commented Feb 27, 2022

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@alberussoftware
Copy link

Such an annoying bug. Are there any rough plans for when it will be fixed? @ktoso @DougGregor

@AnthonyLatsis AnthonyLatsis added concurrency Feature: umbrella label for concurrency language features type checker Area → compiler: Semantic analysis actor Feature → concurrency: `actor` declarations swift 5.9 default arguments Feature: default arguments for value parameters actor isolation Feature → concurrency: Actor isolation unexpected error Bug: Unexpected error labels May 2, 2023
@vykut
Copy link

vykut commented Jun 15, 2023

@AnthonyLatsis are there plans to fix this bug in Swift 5.9?

@AnthonyLatsis
Copy link
Collaborator

I have a feeling fixing this might warrant a formal evolution proposal that outlines the semantics and restrictions for public approval, so I suppose not, but we should really ask the concurrency experts (@ktoso or @DougGregor ping).

@ktoso ktoso changed the title [SR-15916] Not implemented: @MainActor-isolated default arguments for @MainActor-isolated functions [SR-15916] @MainActor-isolated default arguments for @MainActor-isolated functions Jul 13, 2023
@ktoso
Copy link
Member

ktoso commented Jul 13, 2023

Might need a mini proposal, let me track it with a radar. rdar://112171197

@hborla FYI

@hborla
Copy link
Member

hborla commented Sep 29, 2023

I have a draft implementation of this at #68794. I'm also working on a proposal to detail the semantics. I'm thinking we want similar rules for default value expressions of (global-)actor-isolated instance properties.

@hborla
Copy link
Member

hborla commented Oct 6, 2023

Here's the pitch thread, in case anybody would like to participate in the discussion: https://forums.swift.org/t/pitch-isolated-default-value-expressions/67714

I'm also going to reopen this - it was automatically closed when I merged my implementation PR, but the feature is behind an experimental feature flag.

@hborla hborla reopened this Oct 6, 2023
@hborla
Copy link
Member

hborla commented Jan 23, 2024

The given example compiles under -strict-concurrency=complete in Swift 5.10. This is resolved by #70839

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 actor Feature → concurrency: `actor` declarations 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 default arguments Feature: default arguments for value parameters type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
6 participants