Since enums don't have constructors that can be called from outside, enum classes expose method $INIT as a constructor helper via which enum constructors are called and enum values are created.
And then StaticImportVisitor has this logic to find imported static methods by name and argument types.
Since all enum classes have these standard static methods like $INIT()/values() when enum values in the 2nd enum Bar are being created using static call $INIT(
), StaticImportVisitor, starts searching for $INIT in all static imports and finds it in the first static import Foo itself (as $INIT is a standard method) and because of that enum value for Bar gets typecasted to Foo mistakenly and throws this type-casting error that has been reported.
Made the changes in StaticImportVisitor to invoke $INIT of the correct static-imported enum in such a case.
Fixed it on branches 1.5.x, 1.6.x and trunk.