Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using + Inline + Inline == bad result #9024

Closed
djaonourside opened this issue Dec 11, 2019 · 8 comments
Closed

Using + Inline + Inline == bad result #9024

djaonourside opened this issue Dec 11, 2019 · 8 comments

Comments

@djaonourside
Copy link

@djaonourside djaonourside commented Dec 11, 2019

Haxe 4.0.2, target js

using Test;

class Test {
  static function main() {
    var obj1 = {field1: "value1", field2: "value2"};
    var obj2 = {field1: "value2", field2: "value2"};
    var lang = getLang();
    var f = (o1: Object, o2: Object) -> {
      var value1 = o1.getValue(lang);
      var value2 = o2.getValue(lang);
      return value1.localeCompare(value2);
    };
    var result = f(obj1, obj2);
    trace(result);
  }

  static function getLang() {
    return "en";
  }

  public static inline function getValue(obj: Object, lang: String) {
    return lang == "en" ? obj.field1 : obj.field2;
  }

  public static inline function localeCompare(str1: String, str2: String):Int {
    return js.Syntax.code('{0}.localeCompare({1})', str1, str2);
  }
}

typedef Object = {
  field1: String,
  field2: String
};
@kLabz

This comment has been minimized.

Copy link
Contributor

@kLabz kLabz commented Dec 11, 2019

Seems perfectly fine to me, what's the issue here?

@djaonourside

This comment has been minimized.

Copy link
Author

@djaonourside djaonourside commented Dec 11, 2019

Generated main function returning:
return lang == "en" ? o1.field1 : o1.field2.localeCompare(lang == "en" ? o2.field1 : o2.field2);

@kLabz

This comment has been minimized.

Copy link
Contributor

@kLabz kLabz commented Dec 11, 2019

Indeed, breaks with -D analyzer-optimize.

Please provide more than a Test.hx file when reporting an issue, if we don't know what problem you're having nor how you build the file it's hard to help.

@djaonourside

This comment has been minimized.

Copy link
Author

@djaonourside djaonourside commented Dec 11, 2019

@kLabz , yep there is -D analyzer-optimize. Thank you. I'll take your comment into account.

@RealyUniqueName

This comment has been minimized.

Copy link
Member

@RealyUniqueName RealyUniqueName commented Dec 12, 2019

It's not analyzer's fault. It's genjs removes parentheses around ternary op expression.

@Simn

This comment has been minimized.

Copy link
Member

@Simn Simn commented Dec 12, 2019

\o/

@RealyUniqueName

This comment has been minimized.

Copy link
Member

@RealyUniqueName RealyUniqueName commented Dec 12, 2019

Reduced:

class Main {
  static function main() {
    trace(js.Syntax.code('{0}.localeCompare({1})', "value1" < "value2" ? "value1" : "value2", "str"));
  }
}
@RealyUniqueName

This comment has been minimized.

Copy link
Member

@RealyUniqueName RealyUniqueName commented Dec 12, 2019

Fixed in 3b23395

RealyUniqueName added a commit that referenced this issue Dec 12, 2019
RealyUniqueName added a commit that referenced this issue Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.