-
-
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
Omitting function body when overriding @:coreApi classes. #3285
Comments
Seems fine, but maybe tag with a metadata for more explicit behavior ? |
I would like to see a more general solution to this issue which is not tied to
In Haskell you could now create a concrete type class such as ArrayEq by defining either equals or equalsNot, with equals having a standard implementation of I realize "there"s a macro for that", but if we go for some sort of field copying anyway we might as well do it properly and sell it as compile-time inheritance. |
I"m not sure I follow... |
You want to copy fields from base implementations depending on |
Yeah, but I don"t understand how should that be used. You posted an example with interface, does that mean adding some default implementation to the interface itself? |
That"s just because I needed multiple inheritance which we can"t really do with classes, even at macro-level. But now that you mention it a single inheritance copying solution would still be too limiting for my use case, so it wouldn"t really help much. Anyway, I don"t like our current But this probably leads to traits and language extensions on a too large scale, so I"m not gonna interfere anymore with this particular issue. |
I think |
…ass definition (closes HaxeFoundation#3285)
Pls review #3327 |
…ass definition (closes HaxeFoundation#3285)
…ass definition (closes HaxeFoundation#3285)
This is related to #3285, but it"s also useful in its own right for macro users.
I have implemented something on this branch: https://github.com/HaxeFoundation/haxe/tree/ast_source It has two components:
With this we can express @nadako"s example like so: @:coreApi
class Input {
public function readByte():Int {
return 0;
}
public function readInt8():Int @:useAstSource @:coreApi haxe.io.Input.readInt8;
} Obviously this could be abbreviated further to make it more elegant. |
I wonder to what extent this is actually useful, since we still have to manually provide everything that is required for resolving identifiers in copied untyped AST (imports/usings/fields/etc), I"m a bit concerned that this is too error-prone to be a proper language feature. |
Users certainly have to be aware, but then the same is true for macros that return expressions that are retrieved from external sources. |
I don"t like it that much either, that requires to be able to know in advance which AST will have to be reused, which breaks the separation of implementation between the base api and the platform-specific one. |
You suggested exactly that and I"ve implemented it accordingly. |
My suggestion was to have this done automatically, maybe it"s the case? |
Not yet, but to do "something" automatically you have to implement "something" first. Also I"m not sure how to approach this, i.e. how to detect which classes are core classes. This is especially true for your ideas in #4066. |
This is related to #3285, but it"s also useful in its own right for macro users.
look at Typeload.load_core_class: we"re loading core classes in a separate core context, which have -D coreApi defined |
Yes I figured that out after mentioning it and added it accordingly. I"m a bit concerned that it"s for the most part a pointless waste of memory, but then again it"s hardly going to make any difference in the big picture. |
While working on splitting
haxe.io
stuff, I once again came to think that it would be useful to be able to omit function body for non-extern @:coreApi classes which would mean that function body is copied from the common class.For example:
Comon
haxe.io.Input
Target-specific
haxe.io.Input
The text was updated successfully, but these errors were encountered: