Skip to content

Sema: Look through DotSyntaxBaseIgnored when finding function DeclRefs for rethrows checking. #7754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/Sema/TypeCheckError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,23 @@ class AbstractFunction {
static AbstractFunction decomposeFunction(Expr *fn) {
assert(fn->getValueProvidingExpr() == fn);

// Look through Optional unwraps
while (true) {
// Look through Optional unwraps.
if (auto conversion = dyn_cast<ForceValueExpr>(fn)) {
fn = conversion->getSubExpr()->getValueProvidingExpr();
} else if (auto conversion = dyn_cast<BindOptionalExpr>(fn)) {
fn = conversion->getSubExpr()->getValueProvidingExpr();
// Look through function conversions.
} else if (auto conversion = dyn_cast<FunctionConversionExpr>(fn)) {
fn = conversion->getSubExpr()->getValueProvidingExpr();
// Look through base-ignored qualified references (Module.methodName).
} else if (auto baseIgnored = dyn_cast<DotSyntaxBaseIgnoredExpr>(fn)) {
fn = baseIgnored->getRHS();
} else {
break;
}
}
// Look through function conversions.
while (auto conversion = dyn_cast<FunctionConversionExpr>(fn)) {
fn = conversion->getSubExpr()->getValueProvidingExpr();
}


// Normal function references.
if (auto declRef = dyn_cast<DeclRefExpr>(fn)) {
ValueDecl *decl = declRef->getDecl();
Expand Down
24 changes: 23 additions & 1 deletion test/decl/func/rethrows.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-swift-frontend -typecheck -verify -module-name main %s

/** Basics *******************************************************************/

Expand Down Expand Up @@ -454,3 +454,25 @@ class r24221830 : B24221830 {

}

// rdar://problem/30618853

func gallant(_: () throws -> ()) rethrows {}

func goofus(_ f: () -> ()) {
gallant(f)
main.gallant(f)
}

func goofus(_ f: () throws -> ()) rethrows {
try gallant(f)
try main.gallant(f)
}

struct Foo {
func foo() {}
}

func throwWhileGettingFoo() throws -> Foo.Type { return Foo.self }

(throwWhileGettingFoo()).foo(Foo())() // expected-error {{can throw}}
(try throwWhileGettingFoo()).foo(Foo())()
4 changes: 2 additions & 2 deletions test/stdlib/Renames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ func _HashedCollection<K, V>(x: Dictionary<K, V>, i: Dictionary<K, V>.Index, k:

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