I apologise in advance for this - I'm trying to ask a question without knowing what the question is exactly.
To give some background, I'm looking into object nesting and trying to understand the semantics carefully. As part of that effort, I have arrived at a point of confusion about how an implicit message should be resolved when inheritance and nested classes enter the picture together.
Again, I'm not sure how to articulate the question (I suppose I am even confused about being confused); and so instead I will give an example and then highlight one minor thing and one major thing that I don't understand.
class Example usingPlatform: platform = Value ()(
class A = ()(
public bar = (
^ 'bar invoked via A'.
)
public class Inner = ()(
public foo = (
^ bar.
)
)
)
class B = (A new Inner) ()()
public class C = ()(
public bar = (
^ 'bar invoked via C'.
)
public class B2 = B ()()
)
public main: args = (
B new foo println.
C new B2 new foo println.
^ 0
)
)
So, the first thing to note is that we create an instance of B and send #foo to it (see the #main method). Next, note that B inherits from Inner (the class nested into A). And so consequently at runtime:
1. B inherits from Inner.
2. An instance of Example encloses B.
3. An instance of A encloses Inner.
To give a diagram:
// -> = enclose
// ^ = inherits
A -> Inner
^
Example -> B
Now, in method foo of Inner in A, the resolution of the implicit message send with selector #bar has only part of that picture; just the lexical resolution:
So the resolution is to "start at lexical class Inner" and then "step out once" (from Inner to A). Here's my minor point of confusion: this resolution-picture is different from the run-time picture. If we followed the resolution without thinking carefully, we would resolve to the instance of Example and not the instance of A (since Example encloses B). It seems to me that the only way to get from B to A is:
1. step up from B to Inner
2. step out from Inner to A
Since Newspeak always steps up first, I think that the there must be some hidden logic to get the correct lexical class at runtime, and from that lexical class to find the correct enclosing object (SOMns achieves this by storing the lexical class that handles the send into a field of the Implicit Request's AST node). How do you deal with this for your implementation? I'm aware that I might be mixing up compile and run-time semantics here, apologies again.
Okay. Hopefully, you can see where I'm going for my main point of confusion - can the class C override the bar method and expect that the implicit send for #bar will invoke the override?
After talking with Stefan, he helped me to try this on your Newspeak implementation, and I think in both cases (yours and SOMns) we get the output:
```
bar invoked via A
bar invoked via A
```
And so, I guess the answer is probably "no the override will not be invoked." Can you give confirm if that's the correct output and help me to why C's bar cannot override A's bar in this case? I think it has something to do with the late binding, but I'm tripping over myself trying to give a precise explanation as to why.
Okay, well, that's enough for now. I'd really appreciate help to clarify the above if you have time!