Skip to content

[5.5][CSBindings] Account for literal bindings when checking "subtype of existential" property #37672

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
Jun 2, 2021
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
7 changes: 7 additions & 0 deletions include/swift/Sema/CSBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ class BindingSet {
if (Bindings.empty())
return false;

// Literal requirements always result in a subtype/supertype
// relationship to a concrete type.
if (llvm::any_of(Literals, [](const auto &literal) {
return literal.second.viableAsBinding();
}))
return false;

return llvm::all_of(Bindings, [](const PotentialBinding &binding) {
return binding.BindingType->isExistentialType() &&
binding.Kind == AllowedBindingKind::Subtypes;
Expand Down
27 changes: 27 additions & 0 deletions test/Constraints/protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,30 @@ func test_arg_conformance_with_conditional_reqs(i: Int) {
let _: Int?? = simple(overloaded_result())
let _: Int?? = overloaded(overloaded_result())
}

// rdar://77570994 - regression in type unification for literal collections

protocol Elt {
}

extension Int : Elt {}
extension Int64 : Elt {}
extension Dictionary : Elt where Key == String, Value: Elt {}

struct Object {}

extension Object : ExpressibleByDictionaryLiteral {
init(dictionaryLiteral elements: (String, Elt)...) {
}
}

enum E {
case test(cond: Bool, v: Int64)

var test_prop: Object {
switch self {
case let .test(cond, v):
return ["obj": ["a": v, "b": cond ? 0 : 42]] // Ok
}
}
}