From 4097428df970bf238bf809aa5c8d657d33b3937e Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 1 Mar 2019 09:45:24 -0800 Subject: [PATCH] =?UTF-8?q?[Constraint=20solver]=20Declarations=20with=20I?= =?UTF-8?q?UOs=20don=E2=80=99t=20have=20effective=20overload=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A declaration with an implicitly-unwrapped optional essentially has two effective overload types, because the result might be optional or it might have been forced. Disable computation of the effective overload type in this case. --- lib/Sema/ConstraintSystem.cpp | 5 +++++ test/Constraints/common_type.swift | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index f4274e6574b..80fe5091e96 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -1488,6 +1488,11 @@ Type ConstraintSystem::getEffectiveOverloadType(const OverloadChoice &overload, if (isa(decl)) return Type(); + // Declarations returning unwrapped optionals don't have a single effective + // type. + if (decl->getAttrs().hasAttribute()) + return Type(); + // Retrieve the interface type. auto type = decl->getInterfaceType(); if (!type) { diff --git a/test/Constraints/common_type.swift b/test/Constraints/common_type.swift index 1a3d6a64919..bc96a135509 100644 --- a/test/Constraints/common_type.swift +++ b/test/Constraints/common_type.swift @@ -7,6 +7,9 @@ struct X { subscript(_: Int) -> String { return "" } subscript(_: Double) -> String { return "" } + + func iuo(_: Int) -> Int! { return 0 } + func iuo(_: Double) -> Int! { return 0 } } struct Y { @@ -15,6 +18,9 @@ struct Y { subscript(_: Int) -> Substring { return "" } subscript(_: Double) -> Substring { return "" } + + func iuo(_: Int) -> Double! { return 0 } + func iuo(_: Double) -> Double! { return 0 } } func f(_: Int) -> X { return X() } @@ -29,11 +35,16 @@ func testCallCommonType() { } func testSubscriptCommonType() { - // FIXME: This will work once we have more filtering of subscripts. // CHECK: subscript_expr // CHECK: overload set choice binding $T{{[0-9]+}} := (Int) -> X - // CHECK-NOT: (common result type for $T{{[0-9]+}} is String) + // CHECK: (common result type for $T{{[0-9]+}} is String) // CHECK: (overload set choice binding $T{{[0-9]+}} := (Double) -> Y) - // CHECK-NOT: (common result type for $T{{[0-9]+}} is Substring) + // CHECK: (common result type for $T{{[0-9]+}} is Substring) _ = f(0)[0] } + +func testCommonTypeIUO() { + // CHECK: overload set choice binding $T{{[0-9]+}} := (Int) -> X + // CHECK-NOT: common result type + _ = f(0).iuo(0) +}