Skip to content

Revert "[AST] Paren'd reference to an IUO function crashes the compiler in SILGen" #26988

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
Sep 2, 2019
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
11 changes: 0 additions & 11 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2272,17 +2272,6 @@ namespace {
auto *choiceLocator = cs.getConstraintLocator(locator.withPathElement(
ConstraintLocator::ImplicitlyUnwrappedDisjunctionChoice));

// We won't have a disjunction choice if we have an IUO function call
// wrapped in parens (i.e. '(s.foo)()'), because we only create a
// single constraint to bind to an optional type. So, we can just return
// false here as there's no need to force unwrap.
if (!solution.DisjunctionChoices.count(choiceLocator)) {
auto type = choice.getDecl()->getInterfaceType();
assert((type && type->is<AnyFunctionType>()) &&
"expected a function type");
return false;
}

return solution.getDisjunctionChoice(choiceLocator);
}

Expand Down
27 changes: 1 addition & 26 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2190,34 +2190,9 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
openedFullType,
refType};

// If we have something like '(s.foo)()', where 's.foo()' returns an IUO,
// then we need to only create a single constraint that binds the
// type to an optional.
auto isIUOCallWrappedInParens = [&]() {
auto decl = choice.getDecl();
auto type = decl ? decl->getInterfaceType() : nullptr;
if (!type || !type->is<AnyFunctionType>())
return false;

auto expr = locator->getAnchor();
if (!expr)
return false;

if (isa<CallExpr>(expr)) {
return false;
}

auto parentExpr = getParentExpr(expr);
if (parentExpr && isa<ParenExpr>(parentExpr))
return true;

return false;
};

// In some cases we already created the appropriate bind constraints.
if (!bindConstraintCreated) {
if (choice.isImplicitlyUnwrappedValueOrReturnValue() &&
!isIUOCallWrappedInParens()) {
if (choice.isImplicitlyUnwrappedValueOrReturnValue()) {
// Build the disjunction to attempt binding both T? and T (or
// function returning T? and function returning T).
buildDisjunctionForImplicitlyUnwrappedOptional(boundType, refType,
Expand Down
23 changes: 0 additions & 23 deletions test/Constraints/iuo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,26 +223,3 @@ var y: Int = 2

let r = sr6988(x: x, y: y)
let _: Int = r

// SR-10492

struct SR_10492_S {
func foo() -> Int! { return 0 }
}

let sr_10492_s = SR_10492_S()
let sr_10492_int1: Int = (sr_10492_s.foo)() // expected-error {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
// expected-note@-1 {{coalesce}}{{44-44= ?? <#default value#>}}
// expected-note@-2 {{force-unwrap}}{{44-44=!}}
let sr_10492_int2: Int? = (sr_10492_s.foo)() // Okay


class SR_10492_C1 {
init!() {}
}

class SR_10492_C2 {
init(_ foo: SR_10492_C1) {}
}

let bar = SR_10492_C2(SR_10492_C1()) // Okay
8 changes: 0 additions & 8 deletions validation-test/compiler_crashers_2_fixed/sr10492.swift

This file was deleted.