Skip to content

Commit f0094c2

Browse files
committed
[ClangImporter] Don't import accessors of constants as 'open' if they're static
1 parent 54e4400 commit f0094c2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ ValueDecl *SwiftDeclSynthesizer::createConstant(Identifier name,
426426
/*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(),
427427
params, type, dc);
428428
func->setStatic(isStatic);
429-
func->setAccess(getOverridableAccessLevel(dc));
429+
func->setAccess(isStatic ? AccessLevel::Public
430+
: getOverridableAccessLevel(dc));
430431
func->setIsObjC(false);
431432
func->setIsDynamic(false);
432433

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %empty-directory(%t/src)
2+
// RUN: split-file %s %t/src
3+
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %t/src/main.swift \
5+
// RUN: -import-bridging-header %t/src/test.h \
6+
// RUN: -module-name main -I %t -emit-sil | %FileCheck %s
7+
8+
//--- test.h
9+
#include <objc/objc.h>
10+
11+
@interface MyClass : NSObject
12+
@end
13+
14+
__attribute__((swift_name("MyClass.value")))
15+
static const int MyClassValue = -1;
16+
17+
//--- main.swift
18+
func foo() {
19+
print(MyClass.value)
20+
}
21+
22+
// CHECK: sil shared [transparent] @$sSo7MyClassC5values5Int32VvgZ : $@convention(method) (@thick MyClass.Type) -> Int32 {
23+
// CHECK-NEXT: // %0 "self"
24+
// CHECK-NEXT: bb0(%0 : $@thick MyClass.Type):
25+
// CHECK-NEXT: debug_value %0, let, name "self", argno 1
26+
// CHECK-NEXT: %2 = integer_literal $Builtin.Int32, -1
27+
// CHECK-NEXT: %3 = struct $Int32 (%2)
28+
// CHECK-NEXT: return %3
29+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)