waneck / testrepo

0 stars 0 forks source link

Issue 1821 - Clarification of nullability and optional arguments - haxe #1821

Open waneck opened 11 years ago

waneck commented 11 years ago

[Google Issue #1821 : http://code.google.com/haxe/issues/detail?id=1821] by si...@haxe.org, at 2013-05-16T13:10:15.000Z I came across this today:

class Main { static public function main() { $type(test); // ?i : Int -> Int }

static function test(i = null) {
    return i + i;
}

}

Compiling to swf9 fails, but it is only caught in the generator: In Flash9, null can't be used as basic type Int.

Compilation to C++ succeeds, which makes me wonder if it should. I think either i should be inferred as Null<Int>, or the compiler should complain about it for all static targets.

Any thoughts?

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2013-05-16T15:06:12.000Z] Yes, we should type as Null<Unknown<0>> when we see (i=null) (before the type inference takes place)

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2013-05-16T15:06:44.000Z] But that can wait for 3.2 I think