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
13 changes: 0 additions & 13 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,19 +1885,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, TypeMatchKind kind,
// we hit commit_to_conversions below, but we have to add a token restriction
// to ensure we wrap the metatype value in a metatype erasure.
if (concrete && type2->isExistentialType()) {

// If we're binding to an empty existential, we need to make sure that the
// conversion is valid.
if (kind == TypeMatchKind::BindType &&
type2->isEmptyExistentialComposition()) {

conversionsOrFixes.push_back(ConversionRestrictionKind::Existential);
addConstraint(ConstraintKind::SelfObjectOfProtocol,
type1, type2, getConstraintLocator(locator));

return SolutionKind::Solved;
}

if (kind == TypeMatchKind::ConformsTo) {
conversionsOrFixes.push_back(ConversionRestrictionKind::
MetatypeToExistentialMetatype);
Expand Down
17 changes: 17 additions & 0 deletions test/Constraints/generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,20 @@ Whatever.foo(a: 23) // expected-error {{generic parameter 'A' could not be infer
// <rdar://problem/21718955> Swift useless error: cannot invoke 'foo' with no arguments
Whatever.bar() // expected-error {{generic parameter 'A' could not be inferred}}

// <rdar://problem/27515965> Type checker doesn't enforce same-type constraint if associated type is Any
protocol P27515965 {
associatedtype R
func f() -> R
}

struct S27515965 : P27515965 {
func f() -> Any { return self }
}

struct V27515965 {
init<T : P27515965>(_ tp: T) where T.R == Float {}
}

func test(x: S27515965) -> V27515965 {
return V27515965(x) // expected-error {{generic parameter 'T' could not be inferred}}
}