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-13789] Behavior of contravariance for function type is not consistent. #56186

Closed
swift-ci opened this issue Oct 29, 2020 · 4 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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13789
Radar rdar://problem/70846005
Original Reporter templar (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

Xcode 12.0 Swift 5.3

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 8047a772adea5c8939e1a7a759547124

Issue Description:

class Base {}
class Derived: Base {}

let block = { (_: Base) in }
typealias ClosureType = (Derived) -> Void

// compiler: OK
let closure = block as ClosureType

// compiler: Warning "always true"
// runtime: isSubtype == false
let isSubtype = block is ClosureType

The static and dynamic behavior of contravariance for function type is not consistent, very weird.

@typesanitizer
Copy link

@swift-ci create

@tbkka
Copy link
Contributor

tbkka commented Oct 30, 2020

The `as` form here is handled entirely at compile time; the compiler can build a thunk to translate arguments as necessary. But `is`, `as?`, and `as!` can get processed at run time, and we don't have runtime JIT to build thunks on the fly.

The real bug here is the erroneous compiler warning in the runtime case. We should fix that.

@xedin
Copy link
Member

xedin commented Feb 10, 2021

Fixed by #34980 Thanks again, luciano (JIRA User)! templar (JIRA User) please use next available snapshot of main branch from swift.org to verify and close.

@swift-ci
Copy link
Collaborator Author

Comment by Junkai Wu (JIRA)

Diagnostics message has been fixed.

Now we have warning
"Runtime conversion from '(Base) -> ()' to 'ClosureType' (aka '(Derived) -> ()') is not supported; 'is' test always fails".

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants