Files
swift-mirror/test/Constraints/class_to_object_in_collection.swift
Joe Groff 0f085dc5ec Sema: Apply metatype-to-object conversions even without restriction hints.
In some cases, such as when pushing a collection conversion down to per-element conversions, we'll coerce a subtype metatype to AnyObject, as in:

```
func f(_: [AnyObject]) {}
f([NSString.self, NSObject.self]) // Type checks as [NSObject.Type] converted to [AnyObject]
```

and only record the restriction kinds used in the indirect steps NSString -> NSObject and NSObject.Type -> AnyObject without recording the jump from NSString.Type to AnyObject. coerceToType ought to apply this subtyping rule even without such a hint, though, since the restriction kind is intended only as an optimization. Fixes rdar://problem/42666956 .
2018-08-07 18:14:31 -07:00

20 lines
407 B
Swift

// RUN: %target-typecheck-verify-swift %clang-importer-sdk
// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) -verify %s
// REQUIRES: objc_interop
import Foundation
func f(_: [AnyObject]) {}
func g(_: [Protocol]) {}
f([NSString.self, NSObject.self])
@objc protocol P: AnyObject {}
@objc protocol Q: AnyObject {}
func foo(p: P.Type, pq: (P & Q).Type) {
f([p, pq])
}
g([P.self, Q.self])