[SR-1570] 'Generic parameter 'Result' could not be inferred' compiler error for wrapper functions like autoreleasepool that return the result of their closure argument. #44179
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
Swift 2.2 in Xcode 7.3.1 (7D1014), and swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a
Additional Detail from JIRA
md5: a887c5d29245fd7788e933e40c2bc88a
is duplicated by:
relates to:
Issue Description:
Hello,
It's a very common pattern to write functions that take a closure and return this closure's result. An example is autoreleasepool, since SE-0061.
The most simple one is:
The issue is that Swift compiler (in both versions 2.2 and swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a) outputs an error
Generic parameter 'Result' could not be inferred
whenever the closure contains a line of code followed with a return statement:The workaround is to add explicit type declaration:
The problem is that this workaround is not easy to find for regular users: they complain and report issues.
As for the variant 2 itself, which does not use the returned value, it can be the sign of some unfinished code, or of some actual issue: we need an "unused result" warning, not an error.
The text was updated successfully, but these errors were encountered: