-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
Don't ignore default values of arguments of inlined functions #8397
Don't ignore default values of arguments of inlined functions #8397
Conversation
This doesn't seem quite right because we now handle default values in two places. This PR would introduce unwanted branching in cases where we have all the static information, e.g. if we're calling your Please make sure to check the output without |
Actually, we don't handle default values like that anywhere in the compiler. Generators have to do that manually. And this branching is only inserted on the call site. Original function body is not changed.
Here is the generated js: // Generated by Haxe 4.0.0-rc.3
(function ($global) { "use strict";
var Main = function() { };
Main.main = function() {
console.log("src/Main.hx:3:",10); // This is for `trace(def2(null))` or `trace(def2())`
console.log("src/Main.hx:4:",Main.def(null));
};
Main.def = function(p) {
var p1 = p;
if(p == null) {
p1 = 10;
}
return p1;
};
Main.main();
})({}); |
class Main {
static function main() {
trace(f());
}
static inline function f(p = 10) {
return p;
}
} Compiled to JS without Main.main = function() {
var p = 10;
if(p == null) {
p = 10;
}
console.log("source/Main.hx:3:",p);
}; |
Sorry, I run it with analyzer-optimize |
What would be the correct fix then? var p = null;
trace(f(p)); does it count for |
In that case we have to accept the branching, nothing we can do about it. The analyzer will clean this up where possible and it's fair to require its usage in these situations. |
Fixes #7032