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-11920] Bogus Warning When Invalid Protocol is Used in Existential Position #54339

Closed
CodaFi opened this issue Dec 6, 2019 · 7 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis

Comments

@CodaFi
Copy link
Member

CodaFi commented Dec 6, 2019

Previous ID SR-11920
Radar rdar://problem/57715257
Original Reporter @CodaFi
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug, TypeChecker
Assignee None
Priority Medium

md5: 6a0184667d6dc91a903498b162ead4ab

Issue Description:

protocol P { associatedtype T }
class C : P {}

func i<T: C>(_ x : T?) -> Bool {
  //  warning: checking a value with optional type 'T?' against dynamic type 'P' succeeds whenever the value is non-nil; did you mean to use '!= nil'?
  return x is P
}

This warning's text makes no sense. `P` is not a dynamic protocol and may not be used in existential position. The wording of this diagnostic needs to be amended not to make reference to dynamism when a protocol may not be used in existential position.

@CodaFi
Copy link
Member Author

CodaFi commented Dec 6, 2019

@swift-ci Create

@swift-ci
Copy link
Collaborator

Comment by Tapan Thaker (JIRA)

@CodaFi: I am not clear on the meaning of "dynamic protocol" here. Could you please explain or link me to a reference, if possible.

@CodaFi
Copy link
Member Author

CodaFi commented Dec 13, 2019

To be honest, I’m not sure why that particular description is used. The a protocol without self or associated type constraints has nothing to do with dynamism... That said, there is a dynamic cast involved, so perhaps that was the original intent.

@swift-ci
Copy link
Collaborator

Comment by Ziyuan Zhao (JIRA)

I'll try to fix this

@slavapestov
Copy link
Member

I think this behaves correctly. Since the class C conforms to P, it is true that you can replace the ‘is’ check with ‘!= nil’.

@CodaFi
Copy link
Member Author

CodaFi commented Jan 2, 2020

The diagnostic's wording is still bogus. Its text needs to reflect the the actual situation that's occurred in source. Re-opening this.

@LucianoPAlmeida
Copy link
Collaborator

Resolved by #40811
CodaFi (JIRA User) I'm resolving, but if you still think the wording can improve we can reopen again =]

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants