Skip to content

Ensure override resolution order #362

@tjpalmer

Description

@tjpalmer

Testing python here and not temper-built python, but we likely should test things like this in some funtest across backends.

In example 1, both B and C extend A:

$ interface A { a(): String { "a" } }
interactive#0: A__0
$ interface B extends A {}
interactive#1: B__0
$ interface C extends A { a(): String { "c" } }
interactive#2: C__0
$ class D extends B & C {}
interactive#3: D__0
$ new D().a()
interactive#4: "c"
>>> class A:
...     def a(self): return "a"
...
>>> class B(A): pass
...
>>> class C(A):
...     def a(self): return "c"
...
>>> class D(B, C): pass
...
>>> D().a()
'c'

Those act the same in this case but if C doesn't extend A, Temper interp and Python are different:

$ interface A { a(): String { "a" } }
interactive#0: A__0
$ interface B extends A {}
interactive#1: B__0
$ interface C { a(): String { "c" } }
interactive#2: C__0
$ class D extends B & C {}
interactive#3: D__0
$ new D().a()
interactive#4: "c"
>>> class A:
...     def a(self): return "a"
...
>>> class B(A): pass
...
>>> class C:
...     def a(self): return "c"
...
>>> class D(B, C): pass
...
>>> D().a()
'a'

Apparently, modern Python uses something called C3 linearization. I haven't tested other backend languages at the moment.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions