jdonaldson / promhx

A promise and functional reactive programming library for Haxe
MIT License
145 stars 24 forks source link

Errors compiling on Haxe 3.3.0-RC1 #84

Closed anissen closed 3 years ago

anissen commented 8 years ago

Compiling the following code (using try-haxe.mrcdk.com) on Haxe 3.2.1 works as expected.

import promhx.Deferred;
import promhx.Stream;

class Test {
  static function main() {    
    var ds1 = new Deferred<Int>();
    var ds2 = new Deferred<Int>();
    var s1 = ds1.stream();
    var s2 = ds2.stream();
    Stream.whenever(s1,s2).then(function(x,y) trace(x+y));

    ds1.resolve(2);
    ds2.resolve(3);
  }
}

However, trying to compile using Haxe 3.3.0-RC1 I get the following error on both JavaScript, Flash and Neko targets:

/opt/haxelib/promhx/1,1,0/src/main/promhx/Stream.hx:56: characters 57-70 : 
Cannot use Void as value

This is probably related to https://github.com/jdonaldson/promhx/issues/81. So changing the offending line to

Stream.whenever(s1,s2).then(function(x,y) :Int { trace(x+y); return x+y; });

makes the code run as expected on the Flash and Neko targets. The JavaScript target throws a SyntaxError: Uncaught SyntaxError: In strict mode code, functions can only be declared at top level or inside a block.. The generated JavaScript code looks like this:

Test.main = function() {
var ds1 = new promhx_Deferred();
var ds2 = new promhx_Deferred();
var s1 = ds1.stream();
var s2 = ds2.stream();

{ then : function(f) {
// ...
hoseyjoe commented 7 years ago

Stream.whenever(s1,s2).then(function(x,y) :Int { trace(x+y); return x+y; });

Appears to work in CPP target (openfl) and in Html5 target (openfl html5) now. Perhaps it was resolved in haxe 3.4?