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-14356] Casting from generic placeholder type T to Any? fails, when T resolves to Any?, when build with -swift-version 4.2 #56715

Closed
swift-ci opened this issue Mar 15, 2021 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14356
Radar rdar://problem/75451689
Original Reporter Koninis (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)

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

md5: b26e9023f315d21187a36a6a6d2ae04f

duplicates:

  • SR-4248 Runtime exception casting an Any? nil to a generic optional

Issue Description:

The following code produces different results when compiled with swift 5 compiler with -swift-version 4.2, and when compiled with either a swift 4.2 compiler or a swift 5 compiler(not using -swift-version).

Basically when in source code compatibility mode the casting from T to Any?(Optional) fails when T resolves to Optional.

   func testfunc() -> T {

    let anynil: Any? = nil
    if let castedanynil = anynil as? T {
        print("casting successful")
    }
    else {
        print("casting failed")
    }
    fatalError()

    }

    let lala: Any? = testfunc()

Prints "casting failed" when build with swift 5 compiler with input sources version 4.2 e.g .swift -swift-version 4.2 test.swift
Prints "casting successful" in any other case
for example when complied with Apple Swift version 4.2.1 (swift-4.2.1-RELEASE), also prints "casting successful"

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Christos Koninis (JIRA)

It seems that this is a duplicate of SR-8704 & SR-4248 this behavior was intended because the solution cased a regression.

@xedin
Copy link
Member

xedin commented Mar 17, 2021

As mentioned in SR-4248 the behavior is correct in Swift 5 mode.

@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

3 participants