[SR-893] Compiler fails to infer return type of the transform closure in a map call #43505
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
type checker
Area → compiler: Semantic analysis
Environment
Observed with Xcode 7.2.1 on OS X 10.11.3
Additional Detail from JIRA
md5: c0ac1ad743999c1756dbbe9d58a76fbd
is duplicated by:
relates to:
Issue Description:
When the map method is called with closure for its transform argument, and the closure return type specification is omitted, everything works fine if the type of the returned expression is implicit – for example,
But if the same expression is assigned to a variable, and the variable is returned:
then the compiler gives an error. In Xcode 7.2.1, the error is
It seems that in both calls, the transform closure is returning a String, and the compiler knows it is a String, so the error in the second call looks like a compiler bug.
(Making the return type explicit –
map { _ -> String in ... }
– works around the bug.)The text was updated successfully, but these errors were encountered: