swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.35k stars 10.34k forks source link

[SR-11946] @available does not appear to be working correctly when archiving #54366

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-11946
Radar rdar://problem/57888488
Original Reporter dbeard (JIRA User)
Type Bug

Attachment: Download

Environment Xcode version: Have tested against 11.0 -\> 11.2 OS: 10.15.1 (19B88)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: f2185a923bb5973aa48e49a0224601c0

Issue Description:

Consider the following code:

        var date: Date = Date()
        if #available(iOS 13.0, *) {
            date = Date().advanced(by: TimeInterval(10000))
        } else {
            // Fallback on earlier versions
            date = Date()
        } 

When building for 64 bit simulator or device only, this works correctly (e.g. debug build).

But when any 32 bit arch is contained in the architectures being built for, this fails with the following:

Value of type 'Date' has no member 'advanced' 

I can workaround this with the following:

        var date: Date = Date()
        print(type(of: Date()))
        if #available(iOS 13.0, *) {
            // Why is this #if required for a release config to build?
            // Shouldn't the #available check above be enough?
            #if (arch(x86_64) || arch(arm64))
            date = Date().advanced(by: TimeInterval(10000))
            #else
            date = Date()
            #endif
        } else {
            // Fallback on earlier versions
            date = Date()
        } 

But I think that the failure is a bug. I've attached a sample project that exhibits this issue when building for Release.

beccadax commented 4 years ago

@swift-ci create