From 739ba4bb3908f9dfb02ad3530744c608b6c5f49f Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Mon, 6 Jul 2020 11:46:03 -0700 Subject: [PATCH] [CSBindings] Open collection binding associated with @autoclosure argument To preserve subtype relationship between element types of a collection passed as an argument to a parameter represented by another collection type let's extend opening of the collection types to be done for arguments to @autoclosure parameters as well because implicit closure is transparent to the caller. Resolves: [SR-13135](https://bugs.swift.org/browse/SR-13135) Resolves: rdar://problem/65088975 --- lib/Sema/CSBindings.cpp | 3 ++- test/Constraints/argument_matching.swift | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Sema/CSBindings.cpp b/lib/Sema/CSBindings.cpp index a3e7ce416b79e..76febfc314d99 100644 --- a/lib/Sema/CSBindings.cpp +++ b/lib/Sema/CSBindings.cpp @@ -1034,7 +1034,8 @@ bool TypeVarBindingProducer::computeNext() { auto srcLocator = binding.getLocator(); if (srcLocator && - srcLocator->isLastElement() && + (srcLocator->isLastElement() || + srcLocator->isLastElement()) && !type->hasTypeVariable() && type->isKnownStdlibCollectionType()) { // If the type binding comes from the argument conversion, let's // instead of binding collection types directly, try to bind diff --git a/test/Constraints/argument_matching.swift b/test/Constraints/argument_matching.swift index 1a8a1984faf1a..0a9f9ecb50ef0 100644 --- a/test/Constraints/argument_matching.swift +++ b/test/Constraints/argument_matching.swift @@ -1607,3 +1607,19 @@ struct DiagnoseAllLabels { f(aax: 0, bbx: 1, dd: 3, ff: 5) // expected-error {{incorrect argument labels in call (have 'aax:bbx:dd:ff:', expected 'aa:bb:dd:ff:')}} {{7-10=aa}} {{15-18=bb}} {{none}} } } + +// SR-13135: Type inference regression in Swift 5.3 - can't infer a type of @autoclosure result. +func sr13135() { + struct Foo { + var bar: [Int] = [] + } + + let baz: Int? = nil + + func foo( + _ a: @autoclosure () throws -> T, + _ b: @autoclosure () throws -> T + ) {} + + foo(Foo().bar, [baz]) +}