Skip to content

[CSBindings] Refactor a check to produce follow-up direct supertype b… #30436

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
Mar 16, 2020
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
17 changes: 8 additions & 9 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,15 +1032,6 @@ bool TypeVarBindingProducer::computeNext() {
}
}

if (binding.Kind != BindingKind::Supertypes)
continue;

for (auto supertype : enumerateDirectSupertypes(type)) {
// If we're not allowed to try this binding, skip it.
if (auto simplifiedSuper = CS.checkTypeOfBinding(TypeVar, supertype))
addNewBinding(binding.withType(*simplifiedSuper));
}

auto srcLocator = binding.getLocator();
if (srcLocator &&
srcLocator->isLastElement<LocatorPathElt::ApplyArgToParam>() &&
Expand All @@ -1059,6 +1050,14 @@ bool TypeVarBindingProducer::computeNext() {
->reconstituteSugar(/*recursive=*/false);
addNewBinding(binding.withType(newType));
}

if (binding.Kind == BindingKind::Supertypes) {
for (auto supertype : enumerateDirectSupertypes(type)) {
// If we're not allowed to try this binding, skip it.
if (auto simplifiedSuper = CS.checkTypeOfBinding(TypeVar, supertype))
addNewBinding(binding.withType(*simplifiedSuper));
}
}
}

if (newBindings.empty())
Expand Down
9 changes: 9 additions & 0 deletions test/Constraints/bridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,12 @@ func bridgeTupleToAnyObject() {
func rdar54274245(_ arr: [Any]?) {
_ = (arr ?? []) as [NSObject]
}

// rdar://problem/60501780 - failed to infer NSString as a value type of a dictionary
func rdar60501780() {
func foo(_: [String: NSObject]) {}

func bar(_ v: String) {
foo(["": "", "": v as NSString])
}
}