haxetink / tink_core

Core utilities
https://haxetink.github.io/tink_core
MIT License
118 stars 33 forks source link

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

Closed serjek closed 1 year ago

serjek commented 4 years ago

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 commented 4 years ago

checked with haxe 4.1.2 and 4.1.3

serjek commented 4 years ago

Apparently same applies to Promise.NOISE as well.

back2dos commented 4 years ago

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

serjek commented 4 years ago

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 commented 4 years ago

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

kevinresol commented 3 years ago

I reverted the change due to #158

serjek commented 3 years ago

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

kevinresol commented 3 years ago

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

final promise = if (v == 42) (Promise.NEVER:Promise<String>) else "okay";
back2dos commented 3 years ago

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

back2dos commented 1 year ago

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