Skip to content

Commit 8803281

Browse files
authored
Merge pull request #35701 from xedin/var-cannot-cover-literal
[CSBindings] Literal coverage checking should account for type variab…
2 parents be843ed + 1965f3e commit 8803281

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,13 @@ PotentialBindings::isLiteralCoveredBy(const LiteralRequirement &literal,
538538
break;
539539
}
540540

541-
if (type->isTypeVariableOrMember() || type->isHole())
542-
return std::make_pair(false, Type());
543-
544541
bool requiresUnwrap = false;
545542
do {
543+
// Conformance check on type variable would always return true,
544+
// but type variable can't cover anything until it's bound.
545+
if (type->isTypeVariableOrMember() || type->isHole())
546+
return std::make_pair(false, Type());
547+
546548
if (literal.isCoveredBy(type, CS.DC)) {
547549
return std::make_pair(true, requiresUnwrap ? type : binding.BindingType);
548550
}

test/expr/expressions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ func testNilCoalescePrecedence(cond: Bool, a: Int?, r: ClosedRange<Int>?) {
782782
// ?? should have higher precedence than logical operators like || and comparisons.
783783
if cond || (a ?? 42 > 0) {} // Ok.
784784
if (cond || a) ?? 42 > 0 {} // expected-error {{cannot be used as a boolean}} {{15-15=(}} {{16-16= != nil)}}
785-
// expected-error@-1 {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
786-
// expected-error@-2 {{cannot convert value of type 'Bool' to expected argument type 'Int'}}
785+
// expected-error@-1 {{binary operator '>' cannot be applied to operands of type 'Bool' and 'Int'}} expected-note@-1 {{overloads for '>' exist with these partially matching parameter list}}
786+
// expected-error@-2 {{binary operator '??' cannot be applied to operands of type 'Bool' and 'Int'}}
787787
if (cond || a) ?? (42 > 0) {} // expected-error {{cannot be used as a boolean}} {{15-15=(}} {{16-16= != nil)}}
788788

789789
if cond || a ?? 42 > 0 {} // Parses as the first one, not the others.

0 commit comments

Comments
 (0)