jakt icon indicating copy to clipboard operation
jakt copied to clipboard

Return type not correctly inferred when returning newly constructed instance

Open mnlrsn opened this issue 2 years ago • 1 comments

To reproduce:

class C {

    public function creat() throws {

        let s = true

        return C()
    }

}

function main() {
    println("{}", C::creat())
}

When compiling, the following error from the C++ is produced:

error: no viable conversion from returned value of type 'Jakt::NonnullRefPtr<Jakt::C>' to function return type 'ErrorOr<void>'
return (TRY((C::create())));
       ^~~~~~~~~~~~~~~~~~~~

Workaround: The error goes away and the main() function works are expected if the creat() function is changed to explicitly state the return type:

    public function creat() throws -> C {
         ...
    }

mnlrsn avatar Aug 18 '22 22:08 mnlrsn

Problem also goes away if the assignment in the function body is removed. See #1093.

mnlrsn avatar Aug 18 '22 22:08 mnlrsn

This is basically fixed as we no longer infer the return type of function blocks

awesomekling avatar Feb 18 '23 23:02 awesomekling