Skip to content

Commit 40f1556

Browse files
authored
Merge pull request #77207 from tshortli/inaccessable-accessor-unavailable-storage
Sema: Diagnose accessor exportability even if storage is unavailable
2 parents a313d4f + df6b339 commit 40f1556

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,6 +4037,14 @@ bool swift::diagnoseDeclAvailability(const ValueDecl *D, SourceRange R,
40374037
if (isa<GenericTypeParamDecl>(D))
40384038
return false;
40394039

4040+
if (R.isValid()) {
4041+
if (TypeChecker::diagnoseInlinableDeclRefAccess(R.Start, D, Where))
4042+
return true;
4043+
4044+
if (TypeChecker::diagnoseDeclRefExportability(R.Start, D, Where))
4045+
return true;
4046+
}
4047+
40404048
// Keep track if this is an accessor.
40414049
auto accessor = dyn_cast<AccessorDecl>(D);
40424050

@@ -4047,14 +4055,6 @@ bool swift::diagnoseDeclAvailability(const ValueDecl *D, SourceRange R,
40474055
return false;
40484056
}
40494057

4050-
if (R.isValid()) {
4051-
if (TypeChecker::diagnoseInlinableDeclRefAccess(R.Start, D, Where))
4052-
return true;
4053-
4054-
if (TypeChecker::diagnoseDeclRefExportability(R.Start, D, Where))
4055-
return true;
4056-
}
4057-
40584058
if (diagnoseExplicitUnavailability(D, R, Where, call, Flags))
40594059
return true;
40604060

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 5
2+
3+
// REQUIRES: OS=macosx
4+
5+
public struct HasVarWithInternalAccessor {
6+
@available(macOS, unavailable)
7+
public internal(set) var internalSetterVar: Int {
8+
get { return 1 }
9+
set { } // expected-note {{setter for property 'internalSetterVar' is not '@usableFromInline' or public}}
10+
}
11+
12+
@available(macOS, unavailable)
13+
@inlinable mutating public func inlinable() {
14+
internalSetterVar = 2 // expected-error {{setter for property 'internalSetterVar' is internal and cannot be referenced from an '@inlinable' function}}
15+
}
16+
}

0 commit comments

Comments
 (0)