Unable to override a method (in Behaviour)

Hi all

I was considering to create a new bug report in YouTrack but ... this seems to be so simple and widely used feature that I assume it is more likely I am just dumb.

In simple words - I can't override a method.

Yes, it happened at least several times that I managed to override a method in concept's behavior. This works for abstract methods. For a non-abstract methods this works ... SOMETIMES (?!!).

Finally I decided to isolate the issue. Please find attached MPS project. It is extremely simplistic. There is a language "jekyll" containing only two concepts: Fruit and Apple. Apple extends Fruit. There is a method "name" implemented in Fruit.

I spent about an hour trying to override this method in Apple - no success. While pressing Ctrl+O, the method "name" defined in superclass (Fruit) is just not showing in the popup window. I was hoping there is some trick to enforce the "override" clause, but I failed to find one.

And the naive attempt to override a method by just defining a method with the same signature like a method in superclass - fails. It works in java, but does not work in MPS. Yes, you CAN define such method, but the resulting behavior is not like in object-oriented language. In the attached project you can actually find a proof: I created a simple editor for Fruit concept and I am showing node.name() in this editor. Then I created an instance of Apple...

I am using MPS 3.2 (build=139.2225).

Is this a bug or I am doing something wrong ?

Wojtek
mps-sandbox.zip (53KB)
override-problem-screenshot.png
4 comments
Funny enough ... I found a workaround for this issue. Pretty tricky but works.

If you want to override Fruit.name() method with Apple.name() method, the sequence of steps is:
1. Go to Fruit class and make the Fruit.name() method abstract. The body of the method will disappear (it is ok, no worries).
2. Go to Apple class, to the Behavior tab, press [Ctrl+I].
3. The method Fruit.name() will appear in the popup window.
4. Select it, so the method template will be generated. This template contains our precious "override" clause (bingo!)
5. Implement Apple.name() body as wanted.
6. Go to Apple class again and make the Apple.name() method non-abstract. There is a bug in MPS making the body of the abstract method to re-appear as it was before making the method abstract. Which is very helpful in this case, actually :-)

Pretty convoluted, but the final effect is as desired. As a proof I am attaching the sandbox project with this trick successfully applied to Apple.name() method.
mps-sandbox.zip (54KB)
0
Valcav - thanx again :-) Ok so I was right I was dumb in this case. I somehow missed the whole virtual-non virtual stuff (it is not existing in java, right?).

So my workaround worked just because while you make method abstract, this "virtual" keyword is automatically added and is stays there.

How stupid I am, that is incredible :-)
0
There are many places, where MPS may feel somewhat unintuitive to people with previous deep Java experience. We paid special attention to covering such cases in our introductory materials (tutorials, videos, the user guide).

Vaclav
0

Please sign in to leave a comment.