Skip to content

Commit 28d504d

Browse files
committed
[Sema] Use the most precise TRC to extend when building them lazily
This fixes an issue reported with emit-module-separately where the compiler reports false-errors on availability. rdar://85472278
1 parent b1eb438 commit 28d504d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,8 @@ void TypeChecker::buildTypeRefinementContextHierarchyDelayed(SourceFile &SF, Abs
931931

932932
// Build the refinement context for the function body.
933933
ASTContext &Context = SF.getASTContext();
934-
TypeRefinementContextBuilder Builder(RootTRC, Context);
934+
auto LocalTRC = RootTRC->findMostRefinedSubContext(AFD->getLoc(), Context.SourceMgr);
935+
TypeRefinementContextBuilder Builder(LocalTRC, Context);
935936
Builder.build(AFD);
936937
}
937938

test/Sema/availability_and_delayed_parsing.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
/// Check for reliable availability checking in inlinable code even when
22
/// skipping some function bodies. rdar://82269657
33

4+
/// Default build mode reading everything
45
// RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target %target-cpu-apple-macos10.10 2>&1 \
56
// RUN: | %FileCheck %s --check-prefixes TRC-API,TRC-INLINABLE,TRC-WITHTYPES,TRC-FULL
7+
8+
/// Emit-module-separately mode / for LLDB
69
// RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target %target-cpu-apple-macos10.10 -experimental-skip-non-inlinable-function-bodies-without-types 2>&1 \
710
// RUN: | %FileCheck %s --check-prefixes TRC-API,TRC-INLINABLE,TRC-WITHTYPES,TRC-FULL-NOT
11+
12+
/// InstallAPI mode
813
// RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target %target-cpu-apple-macos10.10 -experimental-skip-non-inlinable-function-bodies 2>&1 \
914
// RUN: | %FileCheck %s --check-prefixes TRC-API,TRC-INLINABLE,TRC-WITHTYPES-NOT,TRC-FULL-NOT
15+
16+
/// Index build mode
1017
// RUN: %target-swift-frontend -typecheck -dump-type-refinement-contexts %s -target %target-cpu-apple-macos10.10 -experimental-skip-all-function-bodies 2>&1 \
1118
// RUN: | %FileCheck %s --check-prefixes TRC-API,TRC-INLINABLE-NOT,TRC-WITHTYPES-NOT,TRC-FULL-NOT
1219

@@ -17,6 +24,26 @@ public func foo() { }
1724
// TRC-API: (root versions=[10.10.0,+Inf)
1825
// TRC-API: (decl versions=[10.12,+Inf) decl=foo()
1926

27+
#if canImport(Swift)
28+
@available(macOS 10.10, *)
29+
extension String {
30+
public var computedVariable: String {
31+
struct SomeTypeToForceCheckingThis {}
32+
33+
if #available(macOS 10.12, *) {
34+
foo()
35+
}
36+
37+
fatalError()
38+
}
39+
}
40+
#endif
41+
// TRC-FULL: (decl versions=[10.10,+Inf) decl=extension.String
42+
// TRC-WITHTYPES: (condition_following_availability versions=[10.12,+Inf)
43+
// TRC-WITHTYPES: (if_then versions=[10.12,+Inf)
44+
// TRC-WITHTYPES-NOT-NOT: (condition_following_availability versions=[10.12,+Inf)
45+
// TRC-WITHTYPES-NOT-NOT: (if_then versions=[10.12,+Inf)
46+
2047
struct S {
2148
fileprivate var actual: [String] = [] {
2249
didSet {

0 commit comments

Comments
 (0)