Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/Constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ Constraint *Constraint::create(ConstraintSystem &cs, ConstraintKind kind,
assert((kind != ConstraintKind::ConformsTo &&
kind != ConstraintKind::NonisolatedConformsTo &&
kind != ConstraintKind::TransitivelyConformsTo) ||
second->isExistentialType());
second->isAnyExistentialType());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we unwrap the metatype before we generate the constraint though, in the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can since we rely on matchExistentialTypes to iteratively match each level of metatype, i.e if you have $T0 <> P.Type, we need to form an unsolved constraint with P.Type since we wouldn't want it to succeed if $T0 ends up being simply S rather than S.Type.


// Literal protocol conformances expect a protocol.
assert((kind != ConstraintKind::LiteralConformsTo) ||
Expand Down
14 changes: 14 additions & 0 deletions test/Constraints/existential_metatypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,17 @@ func parameterizedExistentials() {
var ppt: any PP4<Int>.Type
pt = ppt // expected-error {{cannot assign value of type 'any PP4<Int>.Type' to type 'any P4<Int>.Type'}}
}

func testNestedMetatype() {
struct S: P {}

func bar<T>(_ x: T) -> T.Type { type(of: x) }
func foo(_ x: P.Type.Type) { }

// Make sure we don't crash.
foo(bar(S.self))

// FIXME: Bad diagnostic
// https://github.com/swiftlang/swift/issues/83991
foo(bar(0)) // expected-error {{failed to produce diagnostic for expression}}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"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"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
protocol a let : a.Type.Type = b->c