Skip to content

Commit dffafdb

Browse files
committed
[test] fix tests
1 parent 4f3dff4 commit dffafdb

File tree

6 files changed

+60
-86
lines changed

6 files changed

+60
-86
lines changed

include/swift/AST/NameLookup.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@
3131

3232
namespace swift {
3333
class ASTContext;
34-
class ASTWalker;
3534
class DeclName;
3635
class Type;
3736
class TypeDecl;
3837
class ValueDecl;
3938
struct SelfBounds;
4039
class NominalTypeDecl;
41-
class Evaluator;
42-
4340
namespace ast_scope {
4441
class ASTSourceFileScope;
4542
class ASTScopeImpl;
@@ -644,7 +641,8 @@ class FindLocalVal : public StmtVisitor<FindLocalVal> {
644641
void visitDoCatchStmt(DoCatchStmt *S);
645642

646643
};
647-
644+
645+
648646
/// The bridge between the legacy UnqualifiedLookupFactory and the new ASTScope
649647
/// lookup system
650648
class AbstractASTScopeDeclConsumer {

lib/AST/NameLookup.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,31 +2820,28 @@ CollectedOpaqueReprs swift::collectOpaqueReturnTypeReprs(TypeRepr *r, ASTContext
28202820
if (Ctx.LangOpts.hasFeature(Feature::ImplicitSome))
28212821
return Action::SkipChildren();
28222822
}
2823-
2824-
if (Ctx.LangOpts.hasFeature(Feature::ImplicitSome)) {
2825-
if (auto existential = dyn_cast<ExistentialTypeRepr>(repr)) {
2826-
auto generic = dyn_cast<GenericIdentTypeRepr>(existential->getConstraint());
2827-
if(generic)
2828-
Reprs.push_back(existential);
2829-
auto meta = dyn_cast<MetatypeTypeRepr>(existential->getConstraint());
2830-
Action::VisitChildrenIf(meta || generic);
2831-
}
28322823

2833-
if (auto compositionRepr = dyn_cast<CompositionTypeRepr>(repr)) {
2834-
if (!compositionRepr->isTypeReprAny())
2835-
Reprs.push_back(compositionRepr);
2836-
return Action::SkipChildren();
2837-
} else if (auto generic = dyn_cast<GenericIdentTypeRepr>(repr)) {
2838-
if (!Reprs.empty() && isa<ExistentialTypeRepr>(Reprs.front())){
2839-
Reprs.clear();
2840-
Action::Continue();
2841-
}
2842-
Reprs.push_back(generic);
2843-
} else if (auto identRepr = dyn_cast<IdentTypeRepr>(repr)) {
2844-
if (identRepr->isProtocol(dc))
2845-
Reprs.push_back(identRepr);
2824+
if (!Ctx.LangOpts.hasFeature(Feature::ImplicitSome))
2825+
return Action::Continue();
2826+
2827+
if (auto existential = dyn_cast<ExistentialTypeRepr>(repr)) {
2828+
auto meta = dyn_cast<MetatypeTypeRepr>(existential->getConstraint());
2829+
auto generic = dyn_cast<GenericIdentTypeRepr>(existential->getConstraint());
2830+
if(generic)
2831+
Reprs.push_back(existential);
2832+
return Action::VisitChildrenIf(meta || generic);
2833+
} else if (auto compositionRepr = dyn_cast<CompositionTypeRepr>(repr)) {
2834+
if (!compositionRepr->isTypeReprAny())
2835+
Reprs.push_back(compositionRepr);
2836+
return Action::SkipChildren();
2837+
} else if (auto generic = dyn_cast<GenericIdentTypeRepr>(repr)) {
2838+
// prevent any P<some P>
2839+
if (!Reprs.empty() && isa<ExistentialTypeRepr>(Reprs.front())){
2840+
Reprs.clear();
28462841
}
2847-
2842+
} else if (auto identRepr = dyn_cast<IdentTypeRepr>(repr)) {
2843+
if (identRepr->isProtocol(dc))
2844+
Reprs.push_back(identRepr);
28482845
}
28492846
return Action::Continue();
28502847
}

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "llvm/Support/ErrorHandling.h"
3131

3232
using namespace swift;
33-
using namespace swift::namelookup;
3433

3534
//
3635
// Generic functions
@@ -167,7 +166,6 @@ OpaqueResultTypeRequest::evaluate(Evaluator &evaluator,
167166
genericParamTypes.push_back(paramType);
168167

169168
TypeRepr *constraint = currentRepr;
170-
//auto *constraint = currentRepr;
171169

172170
if (auto opaqueReturn = dyn_cast<OpaqueReturnTypeRepr>(currentRepr)){
173171
constraint = opaqueReturn->getConstraint();

test/type/implicit_some/opaque_parameters.swift

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,38 @@ protocol Q {
1111

1212
extension Int: P { }
1313
extension String: P { }
14+
extension Array: P { }
15+
extension Set: Q {
16+
typealias A = String
1417

15-
// expected-note@+1{{requirement from conditional conformance of '[Double]' to 'Q'}}
16-
extension Array: Q where Element: P, Element: Equatable {
17-
func f() -> Element {
18-
return first!
19-
}
20-
21-
func takesA(_: Element) {}
22-
}
23-
24-
extension Set: Q where Element: P, Element: Equatable { // expected-warning {{redundant conformance constraint 'Element' : 'Equatable'}}
25-
func f() -> Element {
26-
return first!
27-
}
28-
29-
func takesA(_: Element) {}
18+
func f() -> String { }
19+
func takesA(_: String) { }
3020
}
3121

32-
// expected-note@+2{{where 'Q' = 'Int'}}
33-
// expected-note@+1{{in call to function 'takesImplicitQ'}}
3422
func takesImplicitQ(_ q: Q) -> Bool {
3523
// expected-error@+1 {{cannot convert value of type 'Int' to expected argument type '(Q).A'}}
3624
q.takesA(1)
3725

3826
return q.f() == q.f()
3927
}
4028

41-
func testTakesImplicitQ(arrayOfInts: [Int], setOfStrings: Set<String>, i: Int) {
42-
_ = takesImplicitQ(arrayOfInts)
43-
_ = takesImplicitQ(setOfStrings)
44-
_ = takesImplicitQ(i) // expected-error{{global function 'takesImplicitQ' requires that 'Int' conform to 'Q'}}
29+
func testParam(_ a: Collection) -> Bool {
30+
a.isEmpty
31+
}
4532

46-
let f = takesImplicitQ // expected-error{{generic parameter 'Q' could not be inferred}}
47-
let _: ([String]) -> Bool = takesImplicitQ
48-
let _: ([Double]) -> Bool = takesImplicitQ // expected-error{{global function 'takesImplicitQ' requires that 'Double' conform to 'P'}}
49-
_ = f
33+
func testMultiple(_ a: Collection, _ b: Collection) -> Bool {
34+
a.count == b.count
5035
}
5136

52-
// expected-note@+1{{where 'some P' = '[Int]'}}
53-
func takeMultiple<T>(_: T, _: some Q, _: some P) { }
37+
// expected-note@+1{{where 'P' = 'Set<String>'}}
38+
func takeMultiple<T>(_: T, _: Q, _: P) { }
5439

5540
func testTakeMultiple(
5641
arrayOfInts: [Int], setOfStrings: Set<String>, i: Int, d: Double
5742
) {
58-
takeMultiple(d, arrayOfInts, i)
59-
takeMultiple(d, arrayOfInts, arrayOfInts) // expected-error{{global function 'takeMultiple' requires that '[Int]' conform to 'P'}}
43+
takeMultiple(d, setOfStrings, i)
44+
takeMultiple(d,setOfStrings, arrayOfInts)
45+
takeMultiple(d, setOfStrings, setOfStrings) // expected-error{{global function 'takeMultiple' requires that 'Set<String>' conform to 'P'}}
6046
}
6147

6248
// inout
@@ -67,15 +53,17 @@ func testInOut() {
6753
implicitInOut(&i)
6854
}
6955

70-
// Combine with parameterized protocol types
71-
protocol PrimaryCollection<Element>: Collection {}
56+
// Prohibit use of opaque parameters in consuming positions.
57+
typealias FnType<T> = (T) -> Void
58+
59+
func consumingA(fn: (P) -> Void) { } // expected-error{{'some' cannot appear in parameter position in parameter type '(P) -> Void'}}
60+
func consumingB(fn: FnType<P>) { } // expected-error{{'some' cannot appear in parameter position in parameter type '(P) -> Void'}}
7261

73-
extension Array: PrimaryCollection { }
74-
extension Set: PrimaryCollection { }
7562

63+
// TO-DO Handle plain generic opaque parameters
7664
func takePrimaryCollections(
77-
_ strings: PrimaryCollection<String>,
78-
_ ints : PrimaryCollection<Int>
65+
_ strings:some Collection<String>,
66+
_ ints : some Collection<Int>
7967
) {
8068
for s in strings {
8169
let _: String = s
@@ -85,9 +73,9 @@ func takePrimaryCollections(
8573
let _: Int = i
8674
}
8775
}
88-
76+
// TO-DO Handle plain generic opaque parameters
8977
func takeMatchedPrimaryCollections<T: Equatable>(
90-
_ first: PrimaryCollection<T>, _ second: PrimaryCollection<T>
78+
_ first: some Collection<T>, _ second: some Collection<T>
9179
) -> Bool {
9280
first.elementsEqual(second)
9381
}
@@ -100,9 +88,3 @@ func testPrimaries(
10088
_ = takeMatchedPrimaryCollections(arrayOfInts, setOfInts)
10189
_ = takeMatchedPrimaryCollections(arrayOfInts, setOfStrings) // expected-error{{type of expression is ambiguous without more context}}
10290
}
103-
104-
// Prohibit use of opaque parameters in consuming positions.
105-
typealias FnType<T> = (T) -> Void
106-
107-
func consumingA(fn: (P) -> Void) { } // expected-error{{'some' cannot appear in parameter position in parameter type '(P) -> Void'}}
108-
func consumingB(fn: FnType<P>) { } // expected-error{{'some' cannot appear in parameter position in parameter type '(P) -> Void'}}

test/type/implicit_some/opaque_return.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ class SeasonalMenu : Cafe {
2121
func treats() {}
2222
}
2323

24-
func getCurrentMenu () -> some Cafe {
24+
func getCurrentMenu() -> some Cafe {
2525
return SeasonalMenu()
2626
}
2727

2828
var cafe = getCurrentMenu()
2929
cafe.breakfast()
3030
cafe.treats()
3131

32-
// Type alias + custom protocols
32+
// Type alias + protocols
3333
typealias Snack = Shop & Cafe
3434
typealias Meal = Eatery
3535

36-
struct CoffeeShop(): Snack {
36+
struct CoffeeShop: Snack {
3737
func coffee(){ }
3838
func breakfast() { }
3939
func treats(){ }
@@ -54,7 +54,7 @@ class TopTier: Eatery {
5454
func find() -> Eatery { } // expected-error {{function declares an opaque return type, but has no return statements in its body from which to infer an underlying type}}
5555

5656
func find() -> AnyObject {
57-
return CoffeeShop() // expected-error {{return expression of type 'CoffeeBar' expected to be an instance of a class or class-constrained type}}
57+
return CoffeeShop() // expected-error {{return expression of type 'CoffeeShop' expected to be an instance of a class or class-constrained type}}
5858
}
5959

6060
func find() -> Any {
@@ -83,23 +83,23 @@ protocol Basket {
8383
associatedtype Fruit
8484
associatedtype MiniBasket: Basket where MiniBasket.Fruit == Fruit
8585

86-
var fruits: [Fruit] { get set }
87-
var minibaskets: [MiniBasket] { get set }
86+
var fruit: [Fruit] { get set }
87+
var minifruitbasket: [MiniBasket] { get set }
8888
}
8989

9090
struct MyFruit : Basket {
91-
var fruits: [String]
92-
var minibaskets: [FruitforFriend]
91+
var fruit: [String]
92+
var minifruitbasket: [OtherFruit]
9393
}
9494

95-
struct FruitforFriend : Basket {
96-
var fruits: [String]
97-
var minibaskets: [FruitforFriend]
95+
struct OtherFruit : Basket {
96+
var fruit: [String]
97+
var minifruitbasket: [OtherFruit]
9898
}
9999

100100
func eat(_ myfruit: inout Basket) -> Basket {
101-
myfruit.fruits.removeLast()
102-
myfruit.minibaskets.removeLast()
101+
myfruit.fruit.removeLast()
102+
myfruit.minifruitbasket.removeLast()
103103
return myfruit
104104
}
105105

test/type/opaque_parameters.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-redundant-requirements
2-
// RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-redundant-requirements -enable-experimental-implicit-some
32

43
protocol P { }
54

0 commit comments

Comments
 (0)