Skip to content

Commit d3896b0

Browse files
committed
---
yaml --- r: 349544 b: refs/heads/master-next c: ff12d20 h: refs/heads/master
1 parent 7f2e8b3 commit d3896b0

File tree

7 files changed

+34
-5
lines changed

7 files changed

+34
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 5c025a7b77f63ffb1917dc3113ae14a675720a53
3+
refs/heads/master-next: ff12d20a1d8e14fcb31605daa0a9194a84894ac0
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/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 {

branches/master-next/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);

branches/master-next/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);

branches/master-next/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,

branches/master-next/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)