Skip to content

Commit ff12d20

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 5c025a7 + 987e2c6 commit ff12d20

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,12 @@ Type RequirementFailure::getOwnerType() const {
310310
const GenericContext *RequirementFailure::getGenericContext() const {
311311
if (auto *genericCtx = AffectedDecl->getAsGenericContext())
312312
return genericCtx;
313-
return AffectedDecl->getDeclContext()->getAsDecl()->getAsGenericContext();
313+
314+
auto parentDecl = AffectedDecl->getDeclContext()->getAsDecl();
315+
if (!parentDecl)
316+
return nullptr;
317+
318+
return parentDecl->getAsGenericContext();
314319
}
315320

316321
const Requirement &RequirementFailure::getRequirement() const {

lib/Sema/CSDiagnostics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ class RequirementFailure : public FailureDiagnostic {
236236
assert(locator);
237237
assert(isConditional() || Signature);
238238
assert(AffectedDecl);
239+
assert(getRequirementDC() &&
240+
"Couldn't find where the requirement came from?");
241+
assert(getGenericContext() &&
242+
"Affected decl not within a generic context?");
239243

240244
auto reqElt = locator->castLastElementTo<LocatorPathElt::AnyRequirement>();
241245
assert(reqElt.getRequirementKind() == kind);

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,11 +1629,18 @@ ConstraintSystem::matchSuperclassTypes(Type type1, Type type2,
16291629
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
16301630

16311631
auto classDecl2 = type2->getClassOrBoundGenericClass();
1632+
SmallPtrSet<ClassDecl *, 4> superclasses1;
16321633
for (auto super1 = type1->getSuperclass();
16331634
super1;
16341635
super1 = super1->getSuperclass()) {
1635-
if (super1->getClassOrBoundGenericClass() != classDecl2)
1636+
auto superclass1 = super1->getClassOrBoundGenericClass();
1637+
if (superclass1 != classDecl2) {
1638+
// Break if we have circular inheritance.
1639+
if (superclass1 && !superclasses1.insert(superclass1).second)
1640+
break;
1641+
16361642
continue;
1643+
}
16371644

16381645
return matchTypes(super1, type2, ConstraintKind::Bind,
16391646
subflags, locator);

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(Expr *expr) {
425425
// For an apply of a metatype, we have a short-form constructor. Unlike
426426
// other locators to callees, these are anchored on the apply expression
427427
// rather than the function expr.
428-
if (simplifyType(getType(fnExpr))->is<AnyMetatypeType>()) {
428+
auto fnTy = getFixedTypeRecursive(getType(fnExpr), /*wantRValue*/ true);
429+
if (fnTy->is<AnyMetatypeType>()) {
429430
auto *fnLocator =
430431
getConstraintLocator(applyExpr, ConstraintLocator::ApplyFunction);
431432
return getConstraintLocator(fnLocator,

test/Constraints/generics.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ protocol Q {
714714
}
715715

716716
struct SR10694 {
717-
init<T : P>(_ x: T) {} // expected-note 2{{where 'T' = 'T'}}
717+
init<T : P>(_ x: T) {} // expected-note 3{{where 'T' = 'T'}}
718718
func bar<T>(_ x: T, _ s: SR10694, _ q: Q) {
719719
SR10694.self(x) // expected-error {{initializer 'init(_:)' requires that 'T' conform to 'P'}}
720720

@@ -726,6 +726,10 @@ struct SR10694 {
726726

727727
type(of: q)(x) // expected-error {{initializer 'init(_:)' requires that 'T' conform to 'P'}}
728728
// expected-error@-1 {{initializing from a metatype value must reference 'init' explicitly}}
729+
730+
var srTy = SR10694.self
731+
srTy(x) // expected-error {{initializer 'init(_:)' requires that 'T' conform to 'P'}}
732+
// expected-error@-1 {{initializing from a metatype value must reference 'init' explicitly}}
729733
}
730734
}
731735

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// rdar://problem/54296278 - infinite loop
4+
class Foo {}
5+
class Bar: Bar {} // expected-error{{'Bar' inherits from itself}}
6+
func foo(_ o: AnyObject) -> Foo? {
7+
return o as? Bar // expected-error{{cannot convert return expression of type 'Bar?' to return type 'Foo?'}}
8+
}

0 commit comments

Comments
 (0)