Skip to content

Commit 547fdaa

Browse files
authored
Merge pull request #28026 from slavapestov/orts
Small cleanup to aid debugging and some regression tests
2 parents 5f5134c + 35cc303 commit 547fdaa

File tree

4 files changed

+93
-20
lines changed

4 files changed

+93
-20
lines changed

lib/AST/Decl.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,11 @@ AccessLevel ExtensionDecl::getMaxAccessLevel() const {
12561256

12571257
Type ExtensionDecl::getExtendedType() const {
12581258
ASTContext &ctx = getASTContext();
1259-
return evaluateOrDefault(ctx.evaluator,
1260-
ExtendedTypeRequest{const_cast<ExtensionDecl *>(this)},
1261-
ErrorType::get(ctx));
1259+
if (auto type = evaluateOrDefault(ctx.evaluator,
1260+
ExtendedTypeRequest{const_cast<ExtensionDecl *>(this)},
1261+
Type()))
1262+
return type;
1263+
return ErrorType::get(ctx);
12621264
}
12631265

12641266
/// Clone the given generic parameters in the given list. We don't need any
@@ -2881,19 +2883,21 @@ bool ValueDecl::isRecursiveValidation() const {
28812883
}
28822884

28832885
Type ValueDecl::getInterfaceType() const {
2886+
auto &ctx = getASTContext();
2887+
28842888
// Our clients that don't register the lazy resolver are relying on the
28852889
// fact that they can't pull an interface type out to avoid doing work.
28862890
// This is a necessary evil until we can wean them off.
2887-
if (!getASTContext().getLazyResolver()) {
2891+
if (!ctx.getLazyResolver()) {
28882892
return TypeAndAccess.getPointer();
28892893
}
28902894

2891-
if (auto Ty =
2892-
evaluateOrDefault(getASTContext().evaluator,
2895+
if (auto type =
2896+
evaluateOrDefault(ctx.evaluator,
28932897
InterfaceTypeRequest{const_cast<ValueDecl *>(this)},
2894-
ErrorType::get(getASTContext())))
2895-
return Ty;
2896-
return ErrorType::get(getASTContext());
2898+
Type()))
2899+
return type;
2900+
return ErrorType::get(ctx);
28972901
}
28982902

28992903
void ValueDecl::setInterfaceType(Type type) {
@@ -3695,9 +3699,11 @@ SourceRange TypeAliasDecl::getSourceRange() const {
36953699

36963700
Type TypeAliasDecl::getUnderlyingType() const {
36973701
auto &ctx = getASTContext();
3698-
return evaluateOrDefault(ctx.evaluator,
3702+
if (auto type = evaluateOrDefault(ctx.evaluator,
36993703
UnderlyingTypeRequest{const_cast<TypeAliasDecl *>(this)},
3700-
ErrorType::get(ctx));
3704+
Type()))
3705+
return type;
3706+
return ErrorType::get(ctx);
37013707
}
37023708

37033709
void TypeAliasDecl::setUnderlyingType(Type underlying) {
@@ -3728,10 +3734,12 @@ UnboundGenericType *TypeAliasDecl::getUnboundGenericType() const {
37283734

37293735
Type TypeAliasDecl::getStructuralType() const {
37303736
auto &ctx = getASTContext();
3731-
return evaluateOrDefault(
3737+
if (auto type = evaluateOrDefault(
37323738
ctx.evaluator,
37333739
StructuralTypeRequest{const_cast<TypeAliasDecl *>(this)},
3734-
ErrorType::get(ctx));
3740+
Type()))
3741+
return type;
3742+
return ErrorType::get(ctx);
37353743
}
37363744

37373745
Type AbstractTypeParamDecl::getSuperclass() const {
@@ -6313,9 +6321,11 @@ void SubscriptDecl::setIndices(ParameterList *p) {
63136321
Type SubscriptDecl::getElementInterfaceType() const {
63146322
auto &ctx = getASTContext();
63156323
auto mutableThis = const_cast<SubscriptDecl *>(this);
6316-
return evaluateOrDefault(ctx.evaluator,
6324+
if (auto type = evaluateOrDefault(ctx.evaluator,
63176325
ResultTypeRequest{mutableThis},
6318-
ErrorType::get(ctx));
6326+
Type()))
6327+
return type;
6328+
return ErrorType::get(ctx);
63196329
}
63206330

63216331
ObjCSubscriptKind SubscriptDecl::getObjCSubscriptKind() const {
@@ -6943,9 +6953,11 @@ StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
69436953
Type FuncDecl::getResultInterfaceType() const {
69446954
auto &ctx = getASTContext();
69456955
auto mutableThis = const_cast<FuncDecl *>(this);
6946-
return evaluateOrDefault(ctx.evaluator,
6956+
if (auto type = evaluateOrDefault(ctx.evaluator,
69476957
ResultTypeRequest{mutableThis},
6948-
ErrorType::get(ctx));
6958+
Type()))
6959+
return type;
6960+
return ErrorType::get(ctx);
69496961
}
69506962

69516963
bool FuncDecl::isUnaryOperator() const {

test/Parse/confusables.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ if (true ꝸꝸꝸ false) {} // expected-note {{identifier 'ꝸꝸꝸ' contains
1919
// expected-error @+2 {{expected ',' separator}}
2020
// expected-error @+1 {{type '(Int, Int)' cannot conform to 'BinaryInteger'; only struct/enum/class types can conform to protocols}}
2121
if (55) == 0 {} // expected-note {{unicode character '‒' looks similar to '-'; did you mean to use '-'?}} {{7-10=-}}
22-
// expected-note @-1 {{required by referencing operator function '==' on 'BinaryInteger' where}}
22+
// expected-note @-1 {{required by referencing operator function '==' on 'BinaryInteger' where 'Self' = '(Int, Int)'}}
2323

24-
// FIXME: rdar://56002633
25-
// Above note should read "required by referencing operator function '==' on 'BinaryInteger' where 'Self' = '(Int, Int)'"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend -typecheck %s
2+
3+
extension Sequence {
4+
func sorted<T: Comparable, K: KeyPath<Element, T>>(by keyPath: K) -> Array<Element> {
5+
self.sorted { $0[keyPath:keyPath] < $1[keyPath:keyPath] }
6+
}
7+
}
8+
9+
struct Foo {
10+
let a: Int
11+
}
12+
13+
func main() {
14+
print([Foo(a: 2), Foo(a:1), Foo(a:4), Foo(a:3)].sorted(by: \Foo.a))
15+
}
16+
17+
main()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %target-swift-frontend -typecheck %s
2+
3+
class OFMAttachment : NativeInserting {
4+
typealias SnapshotType = Message.Attachment
5+
}
6+
7+
protocol Snapshotting {
8+
associatedtype NativeType: NativeInserting where NativeType.SnapshotType == Self
9+
associatedtype RecordType: SnapshotRecord where RecordType.SnapshotType == Self
10+
associatedtype ChangeType: SnapshotChange where ChangeType.SnapshotType == Self
11+
12+
static var baseMessageName: String { get }
13+
}
14+
15+
protocol NativeInserting {
16+
associatedtype SnapshotType : Snapshotting where SnapshotType.NativeType == Self
17+
}
18+
19+
protocol SnapshotRecord {
20+
associatedtype SnapshotType : Snapshotting where SnapshotType.RecordType == Self
21+
22+
}
23+
24+
protocol SnapshotChange {
25+
associatedtype SnapshotType : Snapshotting where SnapshotType.ChangeType == Self
26+
}
27+
28+
struct Message {
29+
enum Attachment : Snapshotting {
30+
31+
static var baseMessageName: String = "attachment"
32+
33+
typealias NativeType = OFMAttachment
34+
typealias RecordType = Record
35+
typealias ChangeType = Change
36+
struct Record : SnapshotRecord {
37+
typealias SnapshotType = Message.Attachment
38+
}
39+
40+
struct Change : SnapshotChange {
41+
typealias SnapshotType = Message.Attachment
42+
}
43+
44+
}
45+
}
46+

0 commit comments

Comments
 (0)