Skip to content

Commit 3b2cd33

Browse files
committed
---
yaml --- r: 345567 b: refs/heads/master c: 15f5e4f h: refs/heads/master i: 345565: e651198 345563: 263e2f7 345559: 3086e78 345551: fedfd40 345535: 3196b52
1 parent d8995c1 commit 3b2cd33

File tree

11 files changed

+93
-58
lines changed

11 files changed

+93
-58
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 401b876f4bd302f744f7cad0a21ad5e597a5922c
2+
refs/heads/master: 15f5e4f1b2e25dac29b61df67a560e733ed04bf0
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/Decl.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,14 +1151,6 @@ class RequirementRepr {
11511151
return SecondLayout;
11521152
}
11531153

1154-
/// \brief Retrieve the location of the ':' in an explicitly-written
1155-
/// conformance requirement.
1156-
SourceLoc getColonLoc() const {
1157-
assert(getKind() == RequirementReprKind::TypeConstraint ||
1158-
getKind() == RequirementReprKind::LayoutConstraint);
1159-
return SeparatorLoc;
1160-
}
1161-
11621154
/// \brief Retrieve the first type of a same-type requirement.
11631155
Type getFirstType() const {
11641156
assert(getKind() == RequirementReprKind::SameType);
@@ -1201,10 +1193,9 @@ class RequirementRepr {
12011193
return SecondType;
12021194
}
12031195

1204-
/// \brief Retrieve the location of the '==' in an explicitly-written
1205-
/// same-type requirement.
1206-
SourceLoc getEqualLoc() const {
1207-
assert(getKind() == RequirementReprKind::SameType);
1196+
/// \brief Retrieve the location of the ':' or '==' in an explicitly-written
1197+
/// conformance or same-type requirement respectively.
1198+
SourceLoc getSeparatorLoc() const {
12081199
return SeparatorLoc;
12091200
}
12101201

trunk/include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,11 +1911,11 @@ ERROR(protocol_composition_one_class,none,
19111911

19121912
ERROR(requires_conformance_nonprotocol,none,
19131913
"type %0 constrained to non-protocol, non-class type %1",
1914-
(TypeLoc, TypeLoc))
1914+
(Type, Type))
19151915
ERROR(requires_not_suitable_archetype,none,
19161916
"type %0 in conformance requirement does not refer to a "
19171917
"generic parameter or associated type",
1918-
(TypeLoc))
1918+
(Type))
19191919
WARNING(requires_no_same_type_archetype,none,
19201920
"neither type in same-type constraint (%0 or %1) refers to a "
19211921
"generic parameter or associated type",

trunk/lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ GenericParamList::clone(DeclContext *dc) const {
621621
auto second = reqt.getConstraintLoc();
622622
reqt = RequirementRepr::getTypeConstraint(
623623
first.clone(ctx),
624-
reqt.getColonLoc(),
624+
reqt.getSeparatorLoc(),
625625
second.clone(ctx));
626626
break;
627627
}
@@ -630,7 +630,7 @@ GenericParamList::clone(DeclContext *dc) const {
630630
auto second = reqt.getSecondTypeLoc();
631631
reqt = RequirementRepr::getSameType(
632632
first.clone(ctx),
633-
reqt.getEqualLoc(),
633+
reqt.getSeparatorLoc(),
634634
second.clone(ctx));
635635
break;
636636
}
@@ -639,7 +639,7 @@ GenericParamList::clone(DeclContext *dc) const {
639639
auto layout = reqt.getLayoutConstraintLoc();
640640
reqt = RequirementRepr::getLayoutConstraint(
641641
first.clone(ctx),
642-
reqt.getColonLoc(),
642+
reqt.getSeparatorLoc(),
643643
layout);
644644
break;
645645
}

trunk/lib/AST/GenericSignatureBuilder.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,16 +1454,9 @@ SourceLoc RequirementSource::getLoc() const {
14541454
if (auto typeRepr = getTypeRepr())
14551455
return typeRepr->getStartLoc();
14561456

1457-
if (auto requirementRepr = getRequirementRepr()) {
1458-
switch (requirementRepr->getKind()) {
1459-
case RequirementReprKind::LayoutConstraint:
1460-
case RequirementReprKind::TypeConstraint:
1461-
return requirementRepr->getColonLoc();
1457+
if (auto requirementRepr = getRequirementRepr())
1458+
return requirementRepr->getSeparatorLoc();
14621459

1463-
case RequirementReprKind::SameType:
1464-
return requirementRepr->getEqualLoc();
1465-
}
1466-
}
14671460
if (parent)
14681461
return parent->getLoc();
14691462

@@ -1681,22 +1674,24 @@ const RequirementSource *FloatingRequirementSource::getSource(
16811674
}
16821675

16831676
SourceLoc FloatingRequirementSource::getLoc() const {
1677+
// For an explicit abstract protocol source, we can get a more accurate source
1678+
// location from the written protocol requirement.
1679+
if (kind == Kind::AbstractProtocol && isExplicit()) {
1680+
auto written = protocolReq.written;
1681+
if (auto typeRepr = written.dyn_cast<const TypeRepr *>())
1682+
return typeRepr->getLoc();
1683+
if (auto requirementRepr = written.dyn_cast<const RequirementRepr *>())
1684+
return requirementRepr->getSeparatorLoc();
1685+
}
1686+
16841687
if (auto source = storage.dyn_cast<const RequirementSource *>())
16851688
return source->getLoc();
16861689

16871690
if (auto typeRepr = storage.dyn_cast<const TypeRepr *>())
16881691
return typeRepr->getLoc();
16891692

1690-
if (auto requirementRepr = storage.dyn_cast<const RequirementRepr *>()) {
1691-
switch (requirementRepr->getKind()) {
1692-
case RequirementReprKind::LayoutConstraint:
1693-
case RequirementReprKind::TypeConstraint:
1694-
return requirementRepr->getColonLoc();
1695-
1696-
case RequirementReprKind::SameType:
1697-
return requirementRepr->getEqualLoc();
1698-
}
1699-
}
1693+
if (auto requirementRepr = storage.dyn_cast<const RequirementRepr *>())
1694+
return requirementRepr->getSeparatorLoc();
17001695

17011696
return SourceLoc();
17021697
}
@@ -4586,7 +4581,7 @@ ConstraintResult GenericSignatureBuilder::addLayoutRequirement(
45864581
Impl->HadAnyError = true;
45874582

45884583
Diags.diagnose(source.getLoc(), diag::requires_not_suitable_archetype,
4589-
TypeLoc::withoutLoc(concreteType));
4584+
concreteType);
45904585
return ConstraintResult::Concrete;
45914586
}
45924587

@@ -4719,8 +4714,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
47194714

47204715
Impl->HadAnyError = true;
47214716
Diags.diagnose(source.getLoc(), diag::requires_conformance_nonprotocol,
4722-
TypeLoc::withoutLoc(subjectType),
4723-
TypeLoc::withoutLoc(constraintType));
4717+
subjectType, constraintType);
47244718
}
47254719

47264720
return ConstraintResult::Conflicting;
@@ -4768,7 +4762,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
47684762
if (source.getLoc().isValid()) {
47694763
Impl->HadAnyError = true;
47704764
Diags.diagnose(source.getLoc(), diag::requires_not_suitable_archetype,
4771-
TypeLoc::withoutLoc(subjectType));
4765+
subjectType);
47724766
}
47734767

47744768
return ConstraintResult::Concrete;
@@ -5356,7 +5350,7 @@ GenericSignatureBuilder::addRequirement(const Requirement &req,
53565350
!req.getSecondType()->hasTypeParameter() &&
53575351
!req.getFirstType()->hasError() &&
53585352
!req.getSecondType()->hasError()) {
5359-
Diags.diagnose(reqRepr->getEqualLoc(),
5353+
Diags.diagnose(reqRepr->getSeparatorLoc(),
53605354
diag::requires_no_same_type_archetype,
53615355
req.getFirstType(), req.getSecondType())
53625356
.highlight(reqRepr->getFirstTypeLoc().getSourceRange())

trunk/lib/Sema/TypeCheckProtocol.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,14 @@ swift::matchWitness(
545545
// Result types must match.
546546
// FIXME: Could allow (trivial?) subtyping here.
547547
if (!ignoreReturnType) {
548+
if (reqResultType->hasDynamicSelfType()) {
549+
auto classDecl = witness->getDeclContext()->getSelfClassDecl();
550+
if (!classDecl || classDecl->isFinal() ||
551+
witnessResultType->hasDynamicSelfType())
552+
reqResultType = reqResultType->eraseDynamicSelfType();
553+
witnessResultType = witnessResultType->eraseDynamicSelfType();
554+
}
555+
548556
auto reqTypeIsIUO =
549557
req->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
550558
auto witnessTypeIsIUO =
@@ -2711,11 +2719,11 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
27112719
emitDeclaredHereIfNeeded(diags, diagLoc, witness);
27122720

27132721
if (auto requirementRepr = *constraint) {
2714-
diags.diagnose(requirementRepr->getEqualLoc(),
2722+
diags.diagnose(requirementRepr->getSeparatorLoc(),
27152723
diag::witness_self_weaken_same_type,
27162724
requirementRepr->getFirstType(),
27172725
requirementRepr->getSecondType())
2718-
.fixItReplace(requirementRepr->getEqualLoc(), ":");
2726+
.fixItReplace(requirementRepr->getSeparatorLoc(), ":");
27192727
}
27202728
}
27212729
}

trunk/test/NameBinding/scope_map_lookup.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ protocol P1 {
2323
}
2424

2525
// Protocols involving associated types.
26-
protocol AProtocol { // expected-error{{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}}
26+
protocol AProtocol {
2727
associatedtype e : e
2828
// expected-error@-1 {{inheritance from non-protocol, non-class type 'Self.e'}}
29+
// expected-error@-2 {{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}}
2930
}
3031

3132
// Extensions.

trunk/test/Sema/circular_decl_checking.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ func TopLevelGenericFunc2<T : TopLevelGenericFunc2>(x: T) -> T { return x} // ex
4343
var TopLevelVar: TopLevelVar? { return nil } // expected-error {{use of undeclared type 'TopLevelVar'}}
4444

4545

46-
// FIXME: The first error is redundant, isn't correct in what it states, and
47-
// also should be emitted on the inheritance clause.
48-
protocol AProtocol { // expected-error {{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}}
49-
associatedtype e : e // expected-error {{inheritance from non-protocol, non-class type 'Self.e'}}
46+
// FIXME: The first error is redundant and isn't correct in what it states.
47+
protocol AProtocol {
48+
associatedtype e : e
49+
// expected-error@-1 {{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}}
50+
// expected-error@-2 {{inheritance from non-protocol, non-class type 'Self.e'}}
5051
}
5152

5253

trunk/test/decl/protocol/conforms/self.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,29 @@ extension Node {
8686
}
8787

8888
class IntNode: Node {}
89+
90+
// SR-8902
91+
protocol P8902 {
92+
associatedtype A // expected-note {{protocol requires nested type 'A'; do you want to add it?}}
93+
func f(_ x: A) -> Self
94+
}
95+
struct S : P8902 {
96+
func f(_ x: Bool) -> S { fatalError() }
97+
}
98+
class C8902 : P8902 { // expected-error {{type 'C8902' does not conform to protocol 'P8902'}}
99+
func f(_ x: Bool) -> C8902 { fatalError() }
100+
}
101+
final class C8902b : P8902 {
102+
func f(_ x: Bool) -> C8902b { fatalError() }
103+
}
104+
class C8902c : P8902 {
105+
func f(_ x: Bool) -> Self { fatalError() }
106+
}
107+
protocol P8902complex {
108+
associatedtype A
109+
func f() -> (A, Self?)
110+
}
111+
final class C8902complex : P8902complex {
112+
func f() -> (Bool, C8902complex?) { fatalError() }
113+
}
114+

trunk/test/decl/protocol/req/unsatisfiable.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,30 @@ protocol Base {
3737
associatedtype Assoc
3838
}
3939

40-
// FIXME: The first error is redundant, isn't correct in what it states, and
41-
// also should be emitted on the inheritance clause.
40+
// FIXME: The first error is redundant and isn't correct in what it states.
4241
// FIXME: This used to /not/ error in Swift 3. It didn't impose any statically-
4342
// enforced requirements, but the compiler crashed if you used anything but the
4443
// same type.
45-
protocol Sub1: Base { // expected-error {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}}
46-
associatedtype SubAssoc: Assoc // expected-error {{inheritance from non-protocol, non-class type 'Self.Assoc'}}
44+
protocol Sub1: Base {
45+
associatedtype SubAssoc: Assoc
46+
// expected-error@-1 {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}}
47+
// expected-error@-2 {{inheritance from non-protocol, non-class type 'Self.Assoc'}}
4748
}
48-
// FIXME: This error is incorrect in what it states and should be emitted on
49-
// the where-clause.
50-
protocol Sub2: Base { // expected-error {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}}
51-
associatedtype SubAssoc where SubAssoc: Assoc
49+
50+
// FIXME: This error is incorrect in what it states.
51+
protocol Sub2: Base {
52+
associatedtype SubAssoc where SubAssoc: Assoc // expected-error {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}}
53+
}
54+
55+
struct S {}
56+
57+
// FIX-ME: One of these errors is redundant.
58+
protocol P4 {
59+
associatedtype X : S
60+
// expected-error@-1 {{type 'Self.X' constrained to non-protocol, non-class type 'S'}}
61+
// expected-error@-2 {{inheritance from non-protocol, non-class type 'S'}}
62+
}
63+
64+
protocol P5 {
65+
associatedtype Y where Y : S // expected-error {{type 'Self.Y' constrained to non-protocol, non-class type 'S'}}
5266
}

trunk/validation-test/compiler_crashers_2_fixed/0155-sr7364.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend %s -emit-ir
1+
// RUN: %target-swift-frontend %s -emit-ir
22

33

44
public protocol E {

0 commit comments

Comments
 (0)