MVCoconut / coconut.data

Observable Data Layer.
The Unlicense
20 stars 8 forks source link

Returning Void in switch causes compilation error for @:computed #70

Closed serjek closed 4 years ago

serjek commented 4 years ago

This used to work in previous versions but now it does not (not sure if it's related to coconut.data or tink_state or something else):

@:computed var list:List<String> = [
        for (i in 0...10)
            switch (i % 3) {
                case 0: "OK";
                case _:
            }
    ];

Now it produces following error: Void should be String

As a workaround now array needs to be declared separately:

@:computed var list:List<String> = {
        var ret = [
            for (i in 0...10)
                switch (i % 3) {
                    case 0: "OK";
                    case _:
                }
        ];
        ret;
    };
back2dos commented 4 years ago

That's because tink_lang was removed as a dependency. In tink_lang, comprehensions work a bit differently, as detailed in the docs.

You can either add -lib tink_lang and add @:tink to the models where you wish to use tink_lang's comprehensions, or you change it to standard Haxe by putting continue into empty branches:

  @:computed var list:List<String> = [
    for (i in 0...10)
      switch (i % 3) {
        case 0: "OK";
        case _: continue;
      }
  ];