Skip to content

Commit 1b27618

Browse files
committed
Sema: Teach rethrows checking about OtherConstructorDeclRefExpr
Fixes <https://bugs.swift.org/browse/SR-8788>.
1 parent 532c006 commit 1b27618

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/Sema/TypeCheckError.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ class AbstractFunction {
155155
}
156156
}
157157

158+
// Constructor delegation.
159+
if (auto otherCtorDeclRef = dyn_cast<OtherConstructorDeclRefExpr>(fn)) {
160+
return AbstractFunction(otherCtorDeclRef->getDecl());
161+
}
162+
158163
// Normal function references.
159164
if (auto declRef = dyn_cast<DeclRefExpr>(fn)) {
160165
ValueDecl *decl = declRef->getDecl();

test/decl/func/rethrows.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,3 +584,22 @@ func suchThat<A>(_ x: Box<A>) -> (@escaping (A) -> A) -> Box<A> {
584584
}
585585

586586
Box(unbox: 1) |> suchThat <| { $0 + 1 } // expected-warning {{result of operator '<|' is unused}}
587+
588+
// Constructor delegation -vs- rethrows
589+
class RethrowingConstructor {
590+
init(_ block: () throws -> ()) rethrows {
591+
try block()
592+
}
593+
594+
convenience init(bar: Int) {
595+
self.init {
596+
print("Foo!")
597+
}
598+
}
599+
600+
convenience init(baz: Int) throws {
601+
try self.init {
602+
try throwingFunc()
603+
}
604+
}
605+
}

0 commit comments

Comments
 (0)