Skip to content

What are the expected semantics of changing a method in a class? #35

Open
@ltratt

Description

@ltratt

Consider this program:

mutate_methods = (
    run = (
        mutate_methods methods at:2 put: #a.
        self f.
    )

    f = ( ^#b. )
)

[There is obviously a fragile assumption here that the f is the second method in methods, but let's not worry about that for the time being.]

On Java SOM it crashes on the self f call:

Exception in thread "main" java.lang.ClassCastException: class som.vmobjects.SSymbol cannot be cast to class som.vmobjects.SInvokable (som.vmobjects.SSymbol and som.vmobjects.SInvokable are in unnamed module of loader 'app')

which makes sense. However this seemingly inconsequential variation:

mutate_methods = (
    run = (
        self f.
        mutate_methods methods at:2 put: #a.
        self f.
    )

    f = ( ^#b. )
)

does not crash, presumably because the first self f call populates an inline cache which is not invalidated when the methods Array is mutated.

I assume that this is probably not the intended semantics for this second program (or perhaps it is?), but I'm not sure if e.g. a) SOM should notice the method change b) forbid chnages to the methods Array (e.g. via some sort of "this Array can't be altered?"). Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugFixes an issue, incorrect implementationhelp wantedPull requests very welcome (usually easier than other issues)language designThis issue requires design decisionsspecNeeds specification, or is specification related.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions