Skip to content

Commit 7e6d62d

Browse files
authored
Merge pull request #31643 from hamishknight/metatest
2 parents 98d3a81 + 24e8aa9 commit 7e6d62d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

test/Constraints/metatypes.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ acceptMeta(A) // expected-error {{expected member name or constructor call after
2121

2222
acceptMeta((A) -> Void) // expected-error {{expected member name or constructor call after type name}}
2323
// expected-note@-1 {{use '.self' to reference the type object}}
24+
25+
func id<T>(_ x: T.Type) -> T.Type { x }
26+
27+
// rdar://62890683: Don't allow arbitrary subtyping for a metatype's instance type.
28+
let _: A?.Type = B.self // expected-error {{cannot convert value of type 'B.Type' to specified type 'A?.Type'}}
29+
let _: A?.Type = id(B.self) // expected-error {{cannot convert value of type 'B.Type' to specified type 'A?.Type'}}
30+
let _: S?.Type = id(S.self) // expected-error {{cannot convert value of type 'S.Type' to specified type 'S?.Type'}}
31+

test/Constraints/rdar62890683.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
class C {
4+
init!() {}
5+
}
6+
7+
func foo<T>(_: T.Type, _ fn: () -> T) {}
8+
9+
func test() {
10+
foo(C.self) { C() }
11+
}

0 commit comments

Comments
 (0)