Skip to content

Commit 0609785

Browse files
committed
[AST] Strip InOutType when cloning a parameter.
Fixes rdar://problem/34789779, where initializer inheritance was breaking in the presence of 'inout' parameters.
1 parent b42585b commit 0609785

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,7 +4202,9 @@ ParamDecl::ParamDecl(Specifier specifier,
42024202
ParamDecl::ParamDecl(ParamDecl *PD, bool withTypes)
42034203
: VarDecl(DeclKind::Param, /*IsStatic*/false, PD->getSpecifier(),
42044204
/*IsCaptureList*/false, PD->getNameLoc(), PD->getName(),
4205-
PD->hasType() && withTypes? PD->getType() : Type(),
4205+
PD->hasType() && withTypes
4206+
? PD->getType()->getInOutObjectType()
4207+
: Type(),
42064208
PD->getDeclContext()),
42074209
ArgumentName(PD->getArgumentName()),
42084210
ArgumentNameLoc(PD->getArgumentNameLoc()),
@@ -4215,7 +4217,7 @@ ParamDecl::ParamDecl(ParamDecl *PD, bool withTypes)
42154217
typeLoc.setType(Type());
42164218

42174219
if (withTypes && PD->hasInterfaceType())
4218-
setInterfaceType(PD->getInterfaceType());
4220+
setInterfaceType(PD->getInterfaceType()->getInOutObjectType());
42194221
}
42204222

42214223

test/decl/inherit/initializer.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,34 @@ func testClassInGenericFunc<T>(t: T) {
150150

151151
_ = B(t: t)
152152
}
153+
154+
// rdar://problem/34789779
155+
public class Node {
156+
var data : Data
157+
158+
public struct Data {
159+
var index: Int32 = 0// for helpers
160+
}
161+
162+
init(data: inout Data/*, context: Context*/) {
163+
self.data = data
164+
}
165+
166+
public required init(node: Node) {
167+
data = node.data
168+
}
169+
}
170+
171+
final class SubNode : Node {
172+
var a: Int
173+
174+
required init(node: Node) {
175+
a = 1
176+
super.init(node: node)
177+
}
178+
179+
init(data: inout Data, additionalParam: Int) {
180+
a = additionalParam
181+
super.init(data: &data)
182+
}
183+
}

0 commit comments

Comments
 (0)