Skip to content

Default arguments aren't checked against the global actor of their function #63118

@KeithBauerANZ

Description

@KeithBauerANZ

Description

When declaring a function with a global actor requirement, default values of its arguments are checked without that actor requirement.

Steps to reproduce

@MainActor
final class SomeClass {

    static var someConstant: Int { 3 }

    func someMethod(value: Int = SomeClass.someConstant) {}

}

swiftc -strict-concurrency=complete mainactor-default.swift

Expected behavior

The code should compile, since the function must be called on the main actor, it should be OK for the default value of the argument to require the main actor too.

Actual behavior

mainactor-default.swift:6:44: error: main actor-isolated static property 'someConstant' can not be referenced from a non-isolated context
    func someMethod(value: Int = SomeClass.someConstant) {}
                                           ^
mainactor-default.swift:4:16: note: static property declared here
    static var someConstant: Int { 3 }
               ^

Environment

  • swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
    Target: arm64-apple-macosx13.0
  • Xcode 14.2
    Build version 14C18

Metadata

Metadata

Assignees

No one assigned

    Labels

    actorFeature → concurrency: `actor` declarationsactor isolationFeature → concurrency: Actor isolationbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresdefault argumentsFeature: default arguments for value parametersswift 5.9type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions