nac3-spec/toy-impl/inheritance.py

26 lines
740 B
Python

from helper import *
from type_def import *
import copy
def class_fixup(c: ClassType):
if c.checking:
raise CustomError(f'Circular inheritance detected')
if c.checked:
return
c.checking = True
for p in c.parents:
class_fixup(p)
for m in p.methods:
if m in c.methods:
old = p.methods[m]
new = c.methods[m]
if old[0] != new[0] or old[1] != new[1]:
# actually, we should check for equality *modulo variable renaming*
raise CustomError(f'incorrect method signature for {m} in {c.name}')
else:
c.methods[m] = p.methods[m]
c.checking = False
c.checked = True