Skip to content

Commit aa20633

Browse files
authored
[AutoDiff] [Sema] Fix missing access-level mismatch diagnostic in -enable-testing builds. (#33800)
When a derivative function is internal and its original function is public, there should be an error when the derivative is not `@usableFromInline`. This patch fixes a bug where the error does not appear in SwiftPM debug build configurations (or any configurations with `-enable-testing`). `ValueDecl::getEffectiveAccess()` should not be used when we perform formal access checking for AutoDiff-related declaration attributes because it will treat all internal declarations as public when `-enable-testing` is enabled. Instea we should use a combination of `ValueDecl::getFormalAccess()` and `ValueDecl::isUsableFromInline()`. Also, add a `RUN` line with `-enable-testing` to all AutoDiff declaration attribute test files. Resolves SR-13500 (rdar://68336300).
1 parent 9d908ec commit aa20633

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4645,7 +4645,8 @@ static bool typeCheckDerivativeAttr(ASTContext &Ctx, Decl *D,
46454645
if (originalAFD->getFormalAccess() == derivative->getFormalAccess())
46464646
return true;
46474647
return originalAFD->getFormalAccess() == AccessLevel::Public &&
4648-
derivative->getEffectiveAccess() == AccessLevel::Public;
4648+
(derivative->getFormalAccess() == AccessLevel::Public ||
4649+
derivative->isUsableFromInline());
46494650
};
46504651

46514652
// Check access level compatibility for original and derivative functions.

test/AutoDiff/Sema/derivative_attr_type_checking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend-typecheck -verify -disable-availability-checking %s
2+
// RUN: %target-swift-frontend-typecheck -enable-testing -verify -disable-availability-checking %s
23

34
// Swift.AdditiveArithmetic:3:17: note: cannot yet register derivative default implementation for protocol requirements
45

test/AutoDiff/Sema/differentiable_attr_type_checking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend-typecheck -verify -disable-availability-checking %s
2+
// RUN: %target-swift-frontend-typecheck -enable-testing -verify -disable-availability-checking %s
23

34
import _Differentiation
45

test/AutoDiff/Sema/transpose_attr_type_checking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend-typecheck -verify %s
2+
// RUN: %target-swift-frontend-typecheck -enable-testing -verify %s
23

34
import _Differentiation
45

0 commit comments

Comments
 (0)