Skip to content

Commit 754223d

Browse files
authored
Merge pull request #5558 from DougGregor/witness-subst-cleanup
2 parents 136c86b + 852cda6 commit 754223d

File tree

13 files changed

+245
-144
lines changed

13 files changed

+245
-144
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,8 @@ ERROR(property_behavior_invalid_parameter,none,
19061906
"parameter expression provided, but property behavior %0 does not "
19071907
"use it",
19081908
(Identifier))
1909+
ERROR(property_behavior_conformance_broken,none,
1910+
"property behavior for %0 in type %1 is broken", (DeclName, Type))
19091911

19101912
//------------------------------------------------------------------------------
19111913
// Type Check Attributes

lib/AST/ArchetypeBuilder.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,6 @@ bool ArchetypeBuilder::addSameTypeRequirement(Type Reqt1, Type Reqt2,
13011301

13021302
// Require that at least one side of the requirement be a potential archetype.
13031303
if (!T1 && !T2) {
1304-
assert(Source.getLoc().isValid() && "reintroducing invalid requirement");
13051304
Diags.diagnose(Source.getLoc(), diag::requires_no_same_type_archetype);
13061305
return true;
13071306
}
@@ -1489,7 +1488,7 @@ void ArchetypeBuilder::addRequirement(const Requirement &req,
14891488
switch (req.getKind()) {
14901489
case RequirementKind::Superclass: {
14911490
PotentialArchetype *pa = resolveArchetype(req.getFirstType());
1492-
assert(pa && "Re-introducing invalid requirement");
1491+
if (!pa) return;
14931492

14941493
assert(req.getSecondType()->getClassOrBoundGenericClass());
14951494
addSuperclassRequirement(pa, req.getSecondType(), source);
@@ -1498,11 +1497,7 @@ void ArchetypeBuilder::addRequirement(const Requirement &req,
14981497

14991498
case RequirementKind::Conformance: {
15001499
PotentialArchetype *pa = resolveArchetype(req.getFirstType());
1501-
assert(pa && "Re-introducing invalid requirement");
1502-
// FIXME: defensively return if assertions are disabled until we figure out
1503-
// how this situation can occur and fix it properly.
1504-
if (!pa)
1505-
return;
1500+
if (!pa) return;
15061501

15071502
SmallVector<ProtocolDecl *, 4> conformsTo;
15081503
bool existential = req.getSecondType()->isExistentialType(conformsTo);

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,8 @@ namespace {
21532153
auto type = simplifyType(openedType);
21542154
expr->setType(type);
21552155

2156+
if (type->is<UnresolvedType>()) return expr;
2157+
21562158
Type conformingType = type;
21572159
if (auto baseType = conformingType->getAnyOptionalObjectType()) {
21582160
// The type may be optional due to a failable initializer in the

lib/Sema/CodeSynthesis.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,15 +1270,17 @@ void TypeChecker::completePropertyBehaviorStorage(VarDecl *VD,
12701270
// Add accessors to the storage, since we'll need them to satisfy the
12711271
// conformance requirements.
12721272
addTrivialAccessorsToStorage(Storage, *this);
1273-
1273+
1274+
// FIXME: Hack to eliminate spurious diagnostics.
1275+
if (BehaviorStorage->isStatic() != Storage->isStatic()) return;
1276+
12741277
// Add the witnesses to the conformance.
1275-
// FIXME: Dropping substitution.
1276-
BehaviorConformance->setWitness(BehaviorStorage, Storage);
1277-
BehaviorConformance->setWitness(BehaviorStorage->getGetter(),
1278-
Storage->getGetter());
1278+
recordKnownWitness(BehaviorConformance, BehaviorStorage, Storage);
1279+
recordKnownWitness(BehaviorConformance, BehaviorStorage->getGetter(),
1280+
Storage->getGetter());
12791281
if (BehaviorStorage->isSettable(DC))
1280-
BehaviorConformance->setWitness(BehaviorStorage->getSetter(),
1281-
Storage->getSetter());
1282+
recordKnownWitness(BehaviorConformance, BehaviorStorage->getSetter(),
1283+
Storage->getSetter());
12821284
}
12831285

12841286
void TypeChecker::completePropertyBehaviorParameter(VarDecl *VD,
@@ -1433,8 +1435,7 @@ void TypeChecker::completePropertyBehaviorParameter(VarDecl *VD,
14331435
addMemberToContextIfNeeded(Parameter, DC);
14341436

14351437
// Add the witnesses to the conformance.
1436-
// FIXME: Should compute substitutions.
1437-
BehaviorConformance->setWitness(BehaviorParameter, Parameter);
1438+
recordKnownWitness(BehaviorConformance, BehaviorParameter, Parameter);
14381439
}
14391440

14401441
void TypeChecker::completePropertyBehaviorAccessors(VarDecl *VD,

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,8 @@ static Optional<ObjCReason> shouldMarkAsObjC(TypeChecker &TC,
21602160
else if (VD->getOverriddenDecl() && VD->getOverriddenDecl()->isObjC())
21612161
return ObjCReason::OverridesObjC;
21622162
// A witness to an @objc protocol requirement is implicitly @objc.
2163-
else if (!TC.findWitnessedObjCRequirements(
2163+
else if (VD->getDeclContext()->getAsClassOrClassExtensionContext() &&
2164+
!TC.findWitnessedObjCRequirements(
21642165
VD,
21652166
/*anySingleRequirement=*/true).empty())
21662167
return ObjCReason::WitnessToObjC;

0 commit comments

Comments
 (0)