feedback-assistant / reports

Open collection of Apple Feedback Assistant reports
237 stars 2 forks source link

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

Open macmade opened 1 month ago

macmade commented 1 month ago

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