Skip to content

Commit 918bb5c

Browse files
authored
Merge pull request #80940 from kubamracek/clangimport-const-open
[ClangImporter] Don't import accessors of constants as 'open' if they're static
2 parents f424639 + 6325f05 commit 918bb5c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ ValueDecl *SwiftDeclSynthesizer::createConstant(Identifier name,
426426
/*ThrowsLoc=*/SourceLoc(), /*ThrownType=*/TypeLoc(),
427427
params, type, dc);
428428
func->setStatic(isStatic);
429-
func->setAccess(getOverridableAccessLevel(dc));
430429
func->setIsObjC(false);
431430
func->setIsDynamic(false);
432431

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// REQUIRES: objc_interop
9+
10+
//--- test.h
11+
#include <objc/objc.h>
12+
13+
@interface MyClass : NSObject
14+
@end
15+
16+
__attribute__((swift_name("MyClass.value")))
17+
static const int MyClassValue = -1;
18+
19+
//--- main.swift
20+
func foo() {
21+
print(MyClass.value)
22+
}
23+
24+
// CHECK: sil shared [transparent] @$sSo7MyClassC5values5Int32VvgZ : $@convention(method) (@thick MyClass.Type) -> Int32 {
25+
// CHECK-NEXT: // %0 "self"
26+
// CHECK-NEXT: bb0(%0 : $@thick MyClass.Type):
27+
// CHECK-NEXT: debug_value %0, let, name "self", argno 1
28+
// CHECK-NEXT: %2 = integer_literal $Builtin.Int32, -1
29+
// CHECK-NEXT: %3 = struct $Int32 (%2)
30+
// CHECK-NEXT: return %3
31+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)