Skip to content

Commit 483a894

Browse files
authored
Merge pull request #12272 from DougGregor/inout-param-clone
2 parents c694697 + c999f62 commit 483a894

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: not --crash %target-swift-frontend %s -typecheck
2+
public struct Foo<A, B, C> {}
3+
4+
public protocol P {
5+
associatedtype PA
6+
associatedtype PB = Never
7+
associatedtype PC = Never
8+
9+
typealias Context = Foo<PA, PB, PC>
10+
11+
func f1(_ x: Context, _ y: PA)
12+
func f2(_ x: Context, _ y: PB)
13+
func f3(_ x: Context, _ y: PC)
14+
func f4(_ x: Context)
15+
}
16+
17+
public extension P {
18+
public func f1(_ x: Context, _ y: PA) {
19+
}
20+
public func f2(_ x: Context, _ y: PB) {
21+
}
22+
public func f3(_ x: Context, _ y: PC) {
23+
}
24+
public func f4(_ x: Context) {
25+
}
26+
}
27+
28+
public struct S: P {
29+
public typealias PA = String
30+
public typealias PB = Int
31+
32+
public func f1(_ x: Context, _ y: PA) {
33+
}
34+
public func f2(_ x: Context, _ y: PB) {
35+
}
36+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
protocol VectorIndex {
3+
associatedtype Vector8 : Vector where Vector8.Index == Self, Vector8.Element == UInt8
4+
}
5+
enum VectorIndex1 : VectorIndex {
6+
case i0
7+
typealias Vector8 = Vector1<UInt8>
8+
}
9+
protocol Vector {
10+
associatedtype Index: VectorIndex
11+
associatedtype Element
12+
init(elementForIndex: (Index) -> Element)
13+
subscript(index: Index) -> Element { get set }
14+
}
15+
struct Vector1<Element> : Vector {
16+
//typealias Index = VectorIndex1 // Uncomment this line to workaround bug.
17+
var e0: Element
18+
init(elementForIndex: (VectorIndex1) -> Element) {
19+
e0 = elementForIndex(.i0)
20+
}
21+
subscript(index: Index) -> Element {
22+
get { return e0 }
23+
set { e0 = newValue }
24+
}
25+
}
26+
extension Vector where Index == VectorIndex1 {
27+
init(_ e0: Element) { fatalError() }
28+
}

0 commit comments

Comments
 (0)