Skip to content

Commit 1a854e1

Browse files
committed
Sema: Diagnose missing imports in resolveDeclRefExpr().
1 parent 53d6f7d commit 1a854e1

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,14 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
521521
if (inaccessibleResults) {
522522
// FIXME: What if the unviable candidates have different levels of access?
523523
const ValueDecl *first = inaccessibleResults.front().getValueDecl();
524-
Context.Diags.diagnose(
525-
Loc, diag::candidate_inaccessible, first,
526-
first->getFormalAccessScope().accessLevelForDiagnostics());
524+
auto accessLevel =
525+
first->getFormalAccessScope().accessLevelForDiagnostics();
526+
if (accessLevel == AccessLevel::Public &&
527+
diagnoseMissingImportForMember(first, DC, Loc))
528+
return errorResult();
529+
530+
Context.Diags.diagnose(Loc, diag::candidate_inaccessible, first,
531+
accessLevel);
527532

528533
// FIXME: If any of the candidates (usually just one) are in the same
529534
// module we could offer a fix-it.

test/NameLookup/Inputs/members_A.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ infix operator <>
1515
extension X {
1616
public func XinA() { }
1717

18+
public var propXinA: Bool { return true }
19+
1820
public static func <<<(a: Self, b: Self) -> Self { a }
1921
}
2022

test/NameLookup/Inputs/members_B.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import members_A
44
extension X {
55
public func XinB() { }
66

7+
public var propXinB: Bool { return true }
8+
79
public static func >>>(a: Self, b: Self) -> Self { b }
810
}
911

test/NameLookup/Inputs/members_C.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import members_B
55
extension X {
66
public func XinC() { }
77

8+
public var propXinC: Bool { return true }
9+
810
public static func <>(a: Self, b: Self) -> Self { a }
911
}
1012

test/NameLookup/members_transitive.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ func testMembersWithContextualBase() {
3838
takesEnumInC(.caseInC)
3939
}
4040

41+
extension X {
42+
var testProperties: (Bool, Bool, Bool) {
43+
return (
44+
propXinA,
45+
propXinB, // expected-member-visibility-error{{property 'propXinB' is not available due to missing import of defining module 'members_B'}}
46+
propXinC
47+
)
48+
}
49+
}

0 commit comments

Comments
 (0)