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) +}