mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SILGen] InitAccessors: Remap property references into argument references
A reference to an instance property in init accessor body has to be remapped into an argument reference because all of the properties from initialized/accesses lists are passed to init accessors individually via arguments.
This commit is contained in:
@@ -3576,6 +3576,12 @@ static bool isCurrentFunctionReadAccess(SILGenFunction &SGF) {
|
||||
contextAccessorDecl->getAccessorKind() == AccessorKind::Read;
|
||||
}
|
||||
|
||||
static bool isCurrentFunctionInitAccessor(SILGenFunction &SGF) {
|
||||
auto *contextAccessorDecl =
|
||||
dyn_cast_or_null<AccessorDecl>(SGF.FunctionDC->getAsDecl());
|
||||
return contextAccessorDecl && contextAccessorDecl->isInitAccessor();
|
||||
}
|
||||
|
||||
LValue SILGenLValue::visitMemberRefExpr(MemberRefExpr *e,
|
||||
SGFAccessKind accessKind,
|
||||
LValueOptions options) {
|
||||
@@ -3583,6 +3589,19 @@ LValue SILGenLValue::visitMemberRefExpr(MemberRefExpr *e,
|
||||
// that can be an lvalue is a VarDecl.
|
||||
VarDecl *var = cast<VarDecl>(e->getMember().getDecl());
|
||||
|
||||
// A reference to an instance property in init accessor body
|
||||
// has to be remapped into an argument reference because all
|
||||
// of the properties from initialized/accesses lists are passed
|
||||
// to init accessors individually via arguments.
|
||||
if (isCurrentFunctionInitAccessor(SGF)) {
|
||||
if (auto *arg = SGF.isMappedToInitAccessorArgument(var)) {
|
||||
auto subs = e->getMember().getSubstitutions();
|
||||
return emitLValueForNonMemberVarDecl(
|
||||
SGF, e, ConcreteDeclRef(arg, subs), getSubstFormalRValueType(e),
|
||||
accessKind, options, AccessSemantics::Ordinary, None);
|
||||
}
|
||||
}
|
||||
|
||||
auto accessSemantics = e->getAccessSemantics();
|
||||
AccessStrategy strategy =
|
||||
var->getAccessStrategy(accessSemantics,
|
||||
|
||||
Reference in New Issue
Block a user