Skip to content

Commit 627f41c

Browse files
committed
[CS] Fix an overly strict assert
`matchExistentialTypes` can handle existential metatypes, fix the assert to handle that.
1 parent a5a8cf4 commit 627f41c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/Sema/Constraint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ Constraint *Constraint::create(ConstraintSystem &cs, ConstraintKind kind,
784784
assert((kind != ConstraintKind::ConformsTo &&
785785
kind != ConstraintKind::NonisolatedConformsTo &&
786786
kind != ConstraintKind::TransitivelyConformsTo) ||
787-
second->isExistentialType());
787+
second->isAnyExistentialType());
788788

789789
// Literal protocol conformances expect a protocol.
790790
assert((kind != ConstraintKind::LiteralConformsTo) ||

test/Constraints/existential_metatypes.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,17 @@ func parameterizedExistentials() {
119119
var ppt: any PP4<Int>.Type
120120
pt = ppt // expected-error {{cannot assign value of type 'any PP4<Int>.Type' to type 'any P4<Int>.Type'}}
121121
}
122+
123+
func testNestedMetatype() {
124+
struct S: P {}
125+
126+
func bar<T>(_ x: T) -> T.Type { type(of: x) }
127+
func foo(_ x: P.Type.Type) { }
128+
129+
// Make sure we don't crash.
130+
foo(bar(S.self))
131+
132+
// FIXME: Bad diagnostic
133+
// https://github.com/swiftlang/swift/issues/83991
134+
foo(bar(0)) // expected-error {{failed to produce diagnostic for expression}}
135+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"kind":"typecheck","signature":"swift::constraints::Constraint::create(swift::constraints::ConstraintSystem&, swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocator*, llvm::ArrayRef<swift::TypeVariableType*>)","signatureAssert":"Assertion failed: ((kind != ConstraintKind::ConformsTo && kind != ConstraintKind::NonisolatedConformsTo && kind != ConstraintKind::TransitivelyConformsTo) || second->isExistentialType()), function create"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
protocol a let : a.Type.Type = b->c

0 commit comments

Comments
 (0)