-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
Should static extensions really be applied through implicit casts? #5924
Comments
Related: #5790 I think I agree, but I'll have to check the consequences of changing this. |
Does anyone have any opinions on this? It's one of the things I consider breaking for Haxe 4. |
Adding to my "deliberations" above, I would also like to mention that this would also remove some of the problems with operator overloading through static extensions (as far as I understand). |
Juraj's logic makes total sense to me. |
I have no idea why @Simn was unassigned when I just left a comment |
#2152 has a conflicting test, but that's the only failure in our tests. Let's break it |
I'm holding back on this until I have a solution for #7142. |
Is this change intentionally apply only to FYR the following code still generates using Main.FooTools;
using Main.BarTools;
class Main {
static function main() {
var foo:Foo = {i:1}
trace(foo.stringify());
}
}
typedef Base = {i:Int};
@:forward abstract Foo(Base) from Base {}
@:forward abstract Bar(Base) from Base {}
class FooTools {
public static function stringify(v:Foo) return 'Foo ' + v.i;
}
class BarTools {
public static function stringify(v:Bar) return 'Bar ' + v.i;
} |
Having seen #5888 reminded me of how this current behavior creeps me out: if there's a static extension for type
A
and there's an implicit conversion from another typeB
toA
, then all static extensions forA
are applied toB
also.Here's an example:
This strikes me as pretty weird overall and quite inconsistent also. I really think static extensions should behave like methods as far as possible, but certainly not be applied more liberally. If anything, it is
@:forward
overabstract Abstract(Underlying)
that should allow applying static extensions toUnderlying
toAbstract
. The current behavior can be pretty unintuitive and introducing new implicit casts has far reaching and often undesireable effects:I keep on running into this repeatedly and it forces me to think very carefully about the order of my static extensions to avoid passing through unnecessary (and potentially expensive) implicit conversions. Not only that, I have to recheck the order every time I add a new implicit conversion. It is a breaking change of behavior became specified in #2152, but I really think the issue then was that the compiler silently generating invalid code and rejecting the code all together would have been the right call. Since there is no mention of static extensions being applied through implicit casts in the manual, my preference would be not to have to wait for Haxe 4.
The text was updated successfully, but these errors were encountered: