Skip to content

Commit e9544ba

Browse files
committed
Sema: Look through DotSyntaxBaseIgnored when finding function DeclRefs for rethrows checking.
Fixes rdar://problem/30618853.
1 parent 73b1df3 commit e9544ba

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

lib/Sema/TypeCheckError.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,23 @@ class AbstractFunction {
137137
static AbstractFunction decomposeFunction(Expr *fn) {
138138
assert(fn->getValueProvidingExpr() == fn);
139139

140-
// Look through Optional unwraps
141140
while (true) {
141+
// Look through Optional unwraps.
142142
if (auto conversion = dyn_cast<ForceValueExpr>(fn)) {
143143
fn = conversion->getSubExpr()->getValueProvidingExpr();
144144
} else if (auto conversion = dyn_cast<BindOptionalExpr>(fn)) {
145145
fn = conversion->getSubExpr()->getValueProvidingExpr();
146+
// Look through function conversions.
147+
} else if (auto conversion = dyn_cast<FunctionConversionExpr>(fn)) {
148+
fn = conversion->getSubExpr()->getValueProvidingExpr();
149+
// Look through base-ignored qualified references (Module.methodName).
150+
} else if (auto baseIgnored = dyn_cast<DotSyntaxBaseIgnoredExpr>(fn)) {
151+
fn = baseIgnored->getRHS();
146152
} else {
147153
break;
148154
}
149155
}
150-
// Look through function conversions.
151-
while (auto conversion = dyn_cast<FunctionConversionExpr>(fn)) {
152-
fn = conversion->getSubExpr()->getValueProvidingExpr();
153-
}
154-
156+
155157
// Normal function references.
156158
if (auto declRef = dyn_cast<DeclRefExpr>(fn)) {
157159
ValueDecl *decl = declRef->getDecl();

test/decl/func/rethrows.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-swift-frontend -typecheck -verify -module-name main %s
22

33
/** Basics *******************************************************************/
44

@@ -454,3 +454,25 @@ class r24221830 : B24221830 {
454454

455455
}
456456

457+
// rdar://problem/30618853
458+
459+
func gallant(_: () throws -> ()) rethrows {}
460+
461+
func goofus(_ f: () -> ()) {
462+
gallant(f)
463+
main.gallant(f)
464+
}
465+
466+
func goofus(_ f: () throws -> ()) rethrows {
467+
try gallant(f)
468+
try main.gallant(f)
469+
}
470+
471+
struct Foo {
472+
func foo() {}
473+
}
474+
475+
func throwWhileGettingFoo() throws -> Foo.Type { return Foo.self }
476+
477+
(throwWhileGettingFoo()).foo(Foo())() // expected-error {{can throw}}
478+
(try throwWhileGettingFoo()).foo(Foo())()

test/stdlib/Renames.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ func _HashedCollection<K, V>(x: Dictionary<K, V>, i: Dictionary<K, V>.Index, k:
243243

244244
func _ImplicitlyUnwrappedOptional<T>(x: ImplicitlyUnwrappedOptional<T>) {
245245
_ = ImplicitlyUnwrappedOptional<T>() // expected-error {{'init()' is unavailable: Please use nil literal instead.}} {{none}}
246-
try! _ = ImplicitlyUnwrappedOptional<T>.map(x)() { _ in true } // expected-error {{'map' is unavailable: Has been removed in Swift 3.}}
247-
try! _ = ImplicitlyUnwrappedOptional<T>.flatMap(x)() { _ in true } // expected-error {{'flatMap' is unavailable: Has been removed in Swift 3.}}
246+
_ = ImplicitlyUnwrappedOptional<T>.map(x)() { _ in true } // expected-error {{'map' is unavailable: Has been removed in Swift 3.}}
247+
_ = ImplicitlyUnwrappedOptional<T>.flatMap(x)() { _ in true } // expected-error {{'flatMap' is unavailable: Has been removed in Swift 3.}}
248248
// FIXME: No way to call map and flatMap as method?
249249
// _ = (x as ImplicitlyUnwrappedOptional).map { _ in true } // xpected-error {{}} {{none}}
250250
// _ = (x as ImplicitlyUnwrappedOptional).flatMap { _ in true } // xpected-error {{}} {{none}}

0 commit comments

Comments
 (0)