tink_core icon indicating copy to clipboard operation
tink_core copied to clipboard

Compilation error if Promise.NEVER is in condition and preceding the data

Open serjek opened this issue 3 years ago • 9 comments

Consider the following:

function tryGetData():Promise<Data> return shouldHalt ? Promise.NEVER : data;

it will give compilation error unless Promise.NEVER is put after the data or data is wrapped to Promise.resolve. Note that function already has type hint, but it does not help the compiler to cast the Promise.NEVER properly.

serjek avatar Aug 26 '20 10:08 serjek

checked with haxe 4.1.2 and 4.1.3

serjek avatar Aug 26 '20 10:08 serjek

Apparently same applies to Promise.NOISE as well.

serjek avatar Aug 26 '20 10:08 serjek

Hmm, after the changes to NEVER this seems to work fine.

back2dos avatar Aug 29 '20 11:08 back2dos

still repro:

final p = function():Promise<Int> return Promise.resolve(42);
p().next(v -> if (v == 42) Promise.NEVER else "okay").handle(function(o) trace(o));

String should be tink.core.Promise<tink.core.Never> And yes it will compile just fine if string comes first in condition.

serjek avatar Aug 29 '20 23:08 serjek

But this time wrapping string to Promise.resolve does not help ;(

serjek avatar Aug 29 '20 23:08 serjek

I reverted the change due to #158

kevinresol avatar May 14 '21 07:05 kevinresol

Note, now this works with haxe 4.1.5 but does repro with 4.2.2

serjek avatar Aug 19 '21 12:08 serjek

Current workaround is to explicitly type-hint the NEVER value:

final promise = if (v == 42) (Promise.NEVER:Promise<String>) else "okay";

kevinresol avatar Aug 20 '21 11:08 kevinresol

As @nadako suggested, we should probably add static public function never<X>():Promise<X> to Promise and advertise that instead.

back2dos avatar Aug 21 '21 10:08 back2dos

The suggestions from the above comment was actually implemented a while ago.

back2dos avatar May 16 '23 17:05 back2dos