Strange error: bad superclass

I contributed a warning on Scala 2 but not yet on Scala 3.

It’s for this case where you add an object (probably for a helper method of some kind) but the “companion class” is not co-located.

A value on the class path is shadowed by a companion artifact currently compiled; companions must be compiled together.

The Scala 2 REPL had a warning about defining companions that inspired this lint.

The comment shows why I don’t quite remember the mechanics:

Hint if there is an object in scope, in a package, which has a class, and the class path finds it.

2 Likes