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-13025] False positive warning: cast always fails from '(AnyEvent, AnyC)' to 'Container<ConcreteA>' #55470

Closed
DevAndArtist mannequin opened this issue Jun 16, 2020 · 1 comment
Labels
compiler The Swift compiler in itself

Comments

@DevAndArtist
Copy link
Mannequin

DevAndArtist mannequin commented Jun 16, 2020

Previous ID SR-13025
Radar None
Original Reporter @DevAndArtist
Type Sub-task
Status Resolved
Resolution Done
Environment

Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Sub-task
Assignee None
Priority Medium

md5: 62a403d9f34043c6ac5e490d6a87b843

Parent-Task:

  • SR-13088 False positive warning "cast always fails"

Issue Description:

Since some time (I don't remember how long) the compiler emits a ton of false positive warnings in our project.

Here is an example which generates the warning. We're using a `typealias` to sugar a bit the tuple.

protocol AnyC {
  func foo()
}

protocol AnyEvent {}

protocol A {
  associatedtype C: AnyC
}

protocol EventA: A {
  associatedtype Event
}

typealias Container<Namespace>
  = (event: Namespace.Event, c: Namespace.C) where Namespace: EventA

enum ConcreteA: EventA {
  struct C: AnyC {
    func foo() {
      print("ConcreteA")
    }
  }

  enum Event: AnyEvent {
    case test
  }
}

func coordinate(_ event: AnyEvent, from c: AnyC) {
  switch (event, c) {
  // warning: Cast from '(AnyEvent, AnyC)' to unrelated type 'Container<ConcreteA>' (aka '(event: ConcreteA.Event, c: ConcreteA.C)') always fails
  case let container as Container<ConcreteA>:
    container.c.foo()
  default:
    print("default")
  }
}

let event: AnyEvent = ConcreteA.Event.test
let c: AnyC = ConcreteA.C()

coordinate(event, from: c)

There is a workaround for this warning which requires to label the tuple passed to the switch statement, but the above works and used used to work without any warning.

@LucianoPAlmeida
Copy link
Collaborator

@DevAndArtist this is fixed on master, can you please verify on the next available snapshot and close? Thanks 🙂

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant