Skip to content

Commit 4738cbb

Browse files
authored
[cxx-interop] Use the correct access for synthesized setterDecl (#83218)
Not setting this correctly can lead to an assertion failure in the AST verifier: AbstractStorageDecl's setter access is out of sync with the access actually on the setter Fixes #82637 rdar://154685710
1 parent 4b85066 commit 4738cbb

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static AccessorDecl *makeFieldSetterDecl(ClangImporter::Implementation &Impl,
133133
setterDecl->setIsDynamic(false);
134134
if (!isa<ClassDecl>(importedDecl))
135135
setterDecl->setSelfAccessKind(SelfAccessKind::Mutating);
136-
setterDecl->setAccess(importedFieldDecl->getFormalAccess());
136+
setterDecl->setAccess(importedFieldDecl->getSetterFormalAccess());
137137

138138
return setterDecl;
139139
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-frontend -typecheck -verify -I %t/Inputs %t/main.swift
4+
// RUN: %target-swiftxx-frontend -typecheck -verify -I %t/Inputs %t/main.swift
5+
6+
// Import an anonymous union with const and non-const members. Constant members
7+
// appear within Foo as clang::IndirectFieldDecl and should be imported in Swift
8+
// as computed properties with private setters (since it is possible to change
9+
// the values of const members in C/C++).
10+
11+
//--- Inputs/module.modulemap
12+
module CxxModule { header "header.h" }
13+
14+
//--- Inputs/header.h
15+
#pragma once
16+
17+
struct Foo {
18+
union {
19+
const int constant;
20+
int variable;
21+
};
22+
};
23+
24+
//--- main.swift
25+
import CxxModule
26+
27+
func fooer(_ f: inout Foo) {
28+
let _ = f.variable
29+
let _ = f.constant
30+
f.variable = 42
31+
// f.constant = 42 // FIXME: this should not work (but currently does)
32+
}

0 commit comments

Comments
 (0)