Skip to content

Commit c9eac22

Browse files
authored
Merge pull request #37292 from xedin/rdar-77022842
[CSBindings] Don't infer subtypes/supertype bindings for a closure type
2 parents 6f44ba4 + 3c0388d commit c9eac22

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,15 @@ bool TypeVarBindingProducer::computeNext() {
16461646
newBindings.push_back(std::move(binding));
16471647
};
16481648

1649+
// Let's attempt only directly inferrable bindings for
1650+
// a type variable representing a closure type because
1651+
// such type variables are handled specially and only
1652+
// bound to a type inferred from their expression, having
1653+
// contextual bindings is just a trigger for that to
1654+
// happen.
1655+
if (TypeVar->getImpl().isClosureType())
1656+
return false;
1657+
16491658
for (auto &binding : Bindings) {
16501659
const auto type = binding.BindingType;
16511660
assert(!type->hasError());

test/Constraints/closures.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,3 +1105,12 @@ struct R_76250381<Result, Failure: Error> {
11051105
// expected-error@-1 {{contextual closure type '(Range<Int>.Element) throws -> ()' (aka '(Int) throws -> ()') expects 1 argument, but 3 were used in closure body}}
11061106
(0..<10).map { x, y, z, w in }
11071107
// expected-error@-1 {{contextual closure type '(Range<Int>.Element) throws -> ()' (aka '(Int) throws -> ()') expects 1 argument, but 4 were used in closure body}}
1108+
1109+
// rdar://77022842 - crash due to a missing argument to a ternary operator
1110+
func rdar77022842(argA: Bool? = nil, argB: Bool? = nil) {
1111+
if let a = argA ?? false, if let b = argB ?? {
1112+
// expected-error@-1 {{initializer for conditional binding must have Optional type, not 'Bool'}}
1113+
// expected-error@-2 {{cannot convert value of type '() -> ()' to expected argument type 'Bool?'}}
1114+
// expected-error@-3 {{expected expression in conditional}}
1115+
} // expected-error {{expected '{' after 'if' condition}}
1116+
}

0 commit comments

Comments
 (0)