Skip to content

[GSB] Don't add invalid concrete requirements. #10562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2017
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
3 changes: 3 additions & 0 deletions include/swift/AST/GenericSignatureBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ class GenericSignatureBuilder {
/// the concrete type.
unsigned recursiveConcreteType : 1;

/// Whether we have an invalid concrete type.
unsigned invalidConcreteType : 1;

/// Whether we have detected recursion during the substitution of
/// the superclass type.
unsigned recursiveSuperclassType : 1;
Expand Down
13 changes: 9 additions & 4 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ GenericSignatureBuilder::resolveConcreteConformance(PotentialArchetype *pa,
concrete, proto->getName());
}

paEquivClass->invalidConcreteType = true;
return nullptr;
}

Expand Down Expand Up @@ -1754,7 +1755,8 @@ static void concretizeNestedTypeFromConcreteParent(
}
}

// Error condition: parent did not conform to this protocol, so they
// Error condition: parent did not conform to this protocol, so there is no
// way to resolve the nested type via concrete conformance.
if (!parentConcreteSource) return;

auto source = parentConcreteSource->viaParent(builder, assocType);
Expand Down Expand Up @@ -2448,7 +2450,8 @@ void GenericSignatureBuilder::PotentialArchetype::dump(llvm::raw_ostream &Out,

#pragma mark Equivalence classes
EquivalenceClass::EquivalenceClass(PotentialArchetype *representative)
: recursiveConcreteType(false), recursiveSuperclassType(false)
: recursiveConcreteType(false), invalidConcreteType(false),
recursiveSuperclassType(false)
{
members.push_back(representative);
}
Expand Down Expand Up @@ -3371,6 +3374,7 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
SameTypeConflictCheckedLater());
} else {
equivClass->concreteType = equivClass2->concreteType;
equivClass->invalidConcreteType = equivClass2->invalidConcreteType;
}

equivClass->concreteTypeConstraints.insert(
Expand Down Expand Up @@ -5267,8 +5271,9 @@ void GenericSignatureBuilder::enumerateRequirements(llvm::function_ref<
? knownAnchor->concreteTypeSource
: RequirementSource::forAbstract(archetype);

// Drop recursive concrete-type constraints.
if (equivClass->recursiveConcreteType)
// Drop recursive and invalid concrete-type constraints.
if (equivClass->recursiveConcreteType ||
equivClass->invalidConcreteType)
continue;

f(RequirementKind::SameType, archetype, concreteType, source);
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/same_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func test4<T: Barrable>(_ t: T) -> Y where T.Bar == Y {

func fail3<T: Barrable>(_ t: T) -> X
where T.Bar == X { // expected-error {{'X' does not conform to required protocol 'Fooable'}}
return t.bar
return t.bar // expected-error{{cannot convert return expression of type 'T.Bar' }}
}

func test5<T: Barrable>(_ t: T) -> X where T.Bar.Foo == X {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// RUN: not --crash %target-swift-frontend -emit-ir -primary-file %s

// REQUIRES: asserts
// RUN: not %target-swift-frontend -emit-ir -primary-file %s

struct Version {
}
Expand Down
Loading