Skip to content
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

FB13751434: Compiler fails to report errors accurately in closures #565

Open
macmade opened this issue Sep 25, 2024 · 0 comments
Open

FB13751434: Compiler fails to report errors accurately in closures #565

macmade opened this issue Sep 25, 2024 · 0 comments

Comments

@macmade
Copy link

macmade commented Sep 25, 2024

  • Date: 2024-04-24
  • Resolution: Open
  • Area: Swift Compiler
  • OS: macOS
  • Type: Incorrect/Unexpected Behavior
  • Keywords: xcode, swift, error, warning, closure, compiler

Description

If a syntax error occurs inside a closure, the compiler may fail to report the error.
As an example:

let strings: [ String ] = [ 0, 1, 2, 3 ].compactMap
{
    if $0 == 0
    {
        return nil
    }

    return $0
}

While the syntax error is on return $0, the compiler gives an error on the return nil statement:
'nil' is not compatible with closure result type 'String'

Which is completely garbage since we use compactMap.
It looks like a syntax error inside a closure breaks compiler inference, producing invalid error messages.

If we comment out the return nil, the the compiler is finally able to give a proper error message:
Cannot convert value of type 'Int' to closure result type 'String'

Files

main.swift.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant