Skip to content

Isolated conformance can be escaped by coercing metatype to protocol #91755

Description

@hamishknight

The following "escapes" the MainActor isolated conformance of K to P, incorrectly allowing it to be used in a non-isolated context:

protocol P {
  static func foo()
}
struct S<T: P>: P {
  static func foo() { T.foo() }
}
@MainActor struct K: @MainActor P {
  static func foo() {
    MainActor.preconditionIsolated("💥")
  }
}
await Task.detached {
  let x = S<K>.self
  (x as P.Type).foo()
}.value

Metadata

Metadata

Assignees

No one assigned

    Labels

    actor isolationFeature → concurrency: Actor isolationcompilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featurestype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions