-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
@autoclosure
gets confused when passing a throwing closure as a variable
#59578
Comments
The behavior is correct I think, One thing is that forcing a conversion to erase the auto closure attribute works |
See the docs:
It's also unclear as to what behavior will actually happen here. If I call
If an error is thrown inside Incidentally, if you do it at the top level of the file, instead of inside a
outputs:
This is all particularly obnoxious because the |
Not sure I'm not following ... what I mean is that an autoclosure parameter |
Unfortunately, the |
In general, an |
Duplicate of #43104 |
Describe the bug
Suppose you have the following code:
This results in a compiler error on
foo(bar)
:Add () to forward @autoclosure parameter
.Trying the autofix results in
foo(bar())
, which yields the compiler errorCall can throw but is not marked with 'try'
.Reasonable enough, so let's add a
try
and make the linefoo(try bar())
. Now it fails on the previous line with:Invalid conversion of type () throws -> Void' to non-throwing function type '() -> Void'
.Interestingly enough, the last line works fine if the
foo
call is at the top level of the source file. It is only when it is embedded within a non-throwing closure that this error occurs.This can be worked around by casting
foo
to a closure without@autoclosure
in it:To Reproduce
Steps to reproduce the behavior:
Try to compile the code snippets in the description.
...
Expected behavior
Since
foo
takes a throwing closure, but does not itself throw (presumably it catches any errors and handles them somehow), a call tofoo
should not be interpreted as throwing.Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: