Skip to content

Fix a compile error on JS target (fix #50)#51

Open
jgranick wants to merge 2 commits intomisprintt:masterfrom
jgranick:patch-1
Open

Fix a compile error on JS target (fix #50)#51
jgranick wants to merge 2 commits intomisprintt:masterfrom
jgranick:patch-1

Conversation

@jgranick
Copy link

Using an optional function parameter of a basic type (such as Bool) results in compile errors.

For example, adding to the Calculator mock example:

public function add (value1:Float, value2:Float, _round:Bool = false):Float {
    if (_round) return round(value1 + value2);
    return value1 + value2;
}

Results in this error:

src/math/Calculator.hx:13: lines 13-16 : Field add overloads parent class with different or incomplete type
src/math/Calculator.hx:13: lines 13-16 : value : Float -> value2 : Float -> ?_round : Null<Bool> -> Float should be value : Float -> value2 : Float -> ?_round : Bool -> Float
src/math/Calculator.hx:13: lines 13-16 : Null<Bool> should be Bool

Returning null as the default parameter on all dynamic targets for macro.tools.ComplexTypes results in forcing type Bool to be Null<Bool>, but this was not the original type. On current Haxe development builds, this is the error, on Haxe 3.2.1 it printed "src/Main.hx:28: characters 15-25 : math.CalculatorMocked has no field round" which is more confusing.

Removing the Tools.isStaticPlatform() conditional seems to fix this condition on JavaScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant