pyecoregen icon indicating copy to clipboard operation
pyecoregen copied to clipboard

Wrong code generated for enums

Open alessiostalla opened this issue 1 year ago • 1 comments

See https://github.com/pyecore/pyecore/issues/126#issuecomment-1255030180

Quoting from there, for enums,

pyecoregen generates the wrong code:

for classif in otherClassifiers:
    eClassifiers[classif.name] = classif
    classif.ePackage = eClass

for classif in eClassifiers.values():
    eClass.eClassifiers.append(classif.eClass)

What happens is that, initially, eClassifiers is empty. Then, first, enums are added to eClassifiers, and then the eClass of each object in eClassifiers is added to the EPackage (that for some reason is called eClass). So we have the EEnum class added to the package we're defining! And, of course, it gets removed from the Ecore package, because eClassifiers is a containment relationship. I don't know the purpose of the second for loop, maybe it was to handle custom metaclasses or stuff like that, but it should filter the classes that it puts into eClass, or be removed altogether if it's not necessary.

alessiostalla avatar Nov 08 '22 13:11 alessiostalla