[swift-dev] swift-corelibs-foundation failing in object conversion when building on Darwin host
Joe Groff
jgroff at apple.com
Tue Aug 9 14:02:36 CDT 2016
> On Aug 4, 2016, at 1:21 PM, Philippe Hausler via swift-dev <swift-dev at swift.org> wrote:
>
> With a freshly built toolchain from ToT swift, building ToT swift-corelibs-foundation I am getting some very strange failures in the unit tests:
>
> Test Suite 'TestNSKeyedArchiver' started at 13:15:01.843
> Test Case 'TestNSKeyedArchiver.test_archive_array' started at 13:15:01.843
> assertion failed: file /Volumes/Users/phausler/Documents/Public/swift/swift-corelibs-foundation/Foundation/NSKeyedArchiver.swift, line 23
> 2016-08-04 13:15:07.650689 TestFoundation[47395:4939580] assertion failed: file /Volumes/Users/phausler/Documents/Public/swift/swift-corelibs-foundation/Foundation/NSKeyedArchiver.swift, line 23
> Current stack trace:
>
> this is being caused by the line:
>
> let classReference = innerDecodingContext.dict["$class"] as? CFKeyedArchiverUID
>
> CFKeyedArchiverUID being AnyObject
>
> and
>
> class DecodingContext {
> fileprivate var dict : Dictionary<String, Any>
> …
> }
>
> It claims a conditional cast from Any? to AnyObject always succeeds but it is giving me an unexpected type later on
>
> Changing to:
>
> let classReference = innerDecodingContext.dict["$class"] as CFKeyedArchiverUID?
This is the same problem you raised recently on https://bugs.swift.org/browse/SR-2287. Coercing something to AnyObject on Darwin will bridge it, by boxing if there is no corresponding bridged type. Since you're coercing an Optional, and Optional doesn't bridge, you end up with a boxed Optional. To work around this, you could do 'dict["$class"].map { $0 as AnyObject }'.
-Joe
>
> Then makes the process no longer crash, however it then fails in an even more strange way:
>
>
> guard let root = try unarchiver.decodeTopLevelObjectOfClasses(classes,
> forKey: NSKeyedArchiveRootObjectKey) as? NSObject else {
>
> by expanding that out the decoded object is a NSArray (expected), but that cannot be represented as an NSObject?! This isn’t Swift, this is madness!
>
> Perhaps there is some other failure that I am not seeing underpinning this?
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev
More information about the swift-dev
mailing list