Skip to content

Sema: Diagnose accessor exportability even if storage is unavailable #77207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4037,6 +4037,14 @@ bool swift::diagnoseDeclAvailability(const ValueDecl *D, SourceRange R,
if (isa<GenericTypeParamDecl>(D))
return false;

if (R.isValid()) {
if (TypeChecker::diagnoseInlinableDeclRefAccess(R.Start, D, Where))
return true;

if (TypeChecker::diagnoseDeclRefExportability(R.Start, D, Where))
return true;
}

// Keep track if this is an accessor.
auto accessor = dyn_cast<AccessorDecl>(D);

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

if (R.isValid()) {
if (TypeChecker::diagnoseInlinableDeclRefAccess(R.Start, D, Where))
return true;

if (TypeChecker::diagnoseDeclRefExportability(R.Start, D, Where))
return true;
}

if (diagnoseExplicitUnavailability(D, R, Where, call, Flags))
return true;

Expand Down
16 changes: 16 additions & 0 deletions test/attr/attr_inlinable_accessor_with_unavailable_storage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-typecheck-verify-swift -swift-version 5

// REQUIRES: OS=macosx

public struct HasVarWithInternalAccessor {
@available(macOS, unavailable)
public internal(set) var internalSetterVar: Int {
get { return 1 }
set { } // expected-note {{setter for property 'internalSetterVar' is not '@usableFromInline' or public}}
}

@available(macOS, unavailable)
@inlinable mutating public func inlinable() {
internalSetterVar = 2 // expected-error {{setter for property 'internalSetterVar' is internal and cannot be referenced from an '@inlinable' function}}
}
}