-
-
Notifications
You must be signed in to change notification settings - Fork 408
Improve extension methods #18424
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
base: Pharo14
Are you sure you want to change the base?
Improve extension methods #18424
Conversation
|
There are failing tests that I cannot reproduce locally 😢 I'll check them at some day... |
|
testClassMethodDefinition is a random failure happening from time to time |
|
The ones about unloading are not random failures |
|
To preserve the method that was lost when we edit the extension method you can check something I implemented: We can tag some properties as "properties to persist through recompilation" and it will migrate them from the previous instance to the new compiled method |
|
This should fix your first "What is missing" easily ;) You just need to add a symbol to #propertiesToPersist |
|
Nice. Now I would not do anything with the hidden method. No such dependency or we will obtain chaos. |
|
while this is nice, I fear the excessive "magic" used here. We need to adapt the tooling to make this explicit/visible and then... why not same behavior to each method override ? In the past, I played with the idea of implementing method extension as "Inversed Traits": we add e.g. a ArrayedCollection << #String
traits: { StringExtensionFromMyPackage1 + StringExtensionFromMyPackage2 }
....there is clear where it belongs the extension method (which, by the way, will be able have a protocol more clear than *MyPackage1) And why this are "Inversed traits" ? ArrayedCollection << #String
extensions: { StringExtensionFromMyPackage1 + StringExtensionFromMyPackage2 }
....Of course, order of load here becomes a thing, but also in your solution ;) NOTE: I am not saying we need to implement this, I just wanted to share the solution I had in mind for the same problem (and some others around) ;) |
|
Yes, I was thinking some ideas similar to Inversed Traits. But first I wanted to play a bit with extension (methods) and overrides. So my first approach is to not loose the existing method from one extended one. It should be useful for methods with Anyway, there are many ways to implement that. I just extended the mechanism that is already implemented :) |
0ebc3ec to
cba6dfa
Compare
This PR changes the behaviour of installing/unistalling extension methods.
The case I don't like
Now if you have a method in a package:
And then you install another package with an extension method:
The original method is lost forever.
Then, for example, if you delete or unload the extension package, you object keeps without any method
#m👎What is done here?
This PR changes the compilation of extension methods to:
Something cool that you can do with this:
We could define the extension method based on the replaced method.
We still need a syntax for this, but I could make this extension method using the IRBuilder support:
With result:
Other stuff
What is missing?
There are still some cases to test/support:
super?Done in the sprint 🎉