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-7664] Inconsistent optional casting behaviour with generics #50204

Closed
hamishknight opened this issue May 11, 2018 · 4 comments
Closed

[SR-7664] Inconsistent optional casting behaviour with generics #50204

hamishknight opened this issue May 11, 2018 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-7664
Radar rdar://problem/40171034
Original Reporter @hamishknight
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 4.2-dev (LLVM d9cd6a5c49, Clang ed8876508e, Swift c363dad)
Target: x86_64-apple-darwin17.5.0

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

md5: 241ea289c2d537b07e80e0f58cf55573

is duplicated by:

  • SR-8037 Method generic type inference is broken in Swift 4.2

Issue Description:

This cast succeeds:

func foo(_ t: Int??) -> Int? {
  return t as? Int
}
let x = foo(Int??(3))
print(x as Any) // Optional(3)

but it fails when we use a generic placeholder satisfied by Int rather than Int directly. This cast fails:

func bar<U>(_ t: Int??, _: U.Type) -> U? {
  return t as? U
}

let y = bar(Int??(3), Int.self)
print(y as Any) // nil
@belkadan
Copy link
Contributor

@rudkx, you were looking at some of this, right?

@belkadan
Copy link
Contributor

@swift-ci create

@rudkx
Copy link
Member

rudkx commented May 11, 2018

I was looking at something a little different than this that did not involve generics.

This seems like it must be an issue with the conditional casting support in the runtime.

@mikeash
Copy link
Contributor

mikeash commented May 22, 2018

Fixed in this PR: #16772

@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
Projects
None yet
Development

No branches or pull requests

4 participants