jsx / JSX

JSX - a faster, safer, easier JavaScript
http://jsx.github.io/
MIT License
1.46k stars 102 forks source link

short form function return type variant needs type conversion #310

Closed shibukawa closed 10 years ago

shibukawa commented 10 years ago

This code is invalid for compiler:

import "console. jsx";

class _Main {
    static function func (callback : () -> variant) : void {
        console.log(callback());
    }

    static function func2 () : variant {
        return "hello";
    }

    static function main (argv : string[]) : void {
        _Main.func(() -> { return "hello world"; }); // -> as variant is needed!!
        _Main.func(() ->  "hello world"); // -> as variant is needed!!
        _Main.func(_Main.func2); // -> it's OK
    }
}
kazuho commented 10 years ago

IMO this is the correct behavior and the compiler should continue to work as such.

In case of _Main.func2 the returning type is declared explicitly and thus implicit conversion from string to variant is performed.

In the other two cases, the returning type needs to be deducted from either of function expression or the argument types of the called function, and compiler is reporting errors since the two differ.

shibukawa commented 10 years ago

OK. I understand.