@@ -113,18 +113,20 @@ object SymUtils:
113113 self.isAllOf(Given | Method ) && isCodefined(self.info)
114114
115115 def useCompanionAsSumMirror (using Context ): Boolean =
116+ def companionExtendsSum (using Context ): Boolean =
117+ self.linkedClass.isSubClass(defn.Mirror_SumClass )
116118 self.linkedClass.exists
117- && ! self.is(Scala2x )
118- && (
119- // If the sum type is compiled from source, and `self` is a "generic sum"
120- // then its companion object will become a sum mirror in `posttyper`. (This method
121- // can be called from `typer` when summoning a Mirror.)
122- // However if `self` is from a prior run then we should check that its companion subclasses `Mirror.Sum`.
123- // e.g. before Scala 3.1, hierarchical sum types were not considered "generic sums", so their
124- // companion would not cache the mirror. Companions from TASTy will already be typed as `Mirror.Sum` .
125- self.isDefinedInCurrentRun
126- || self.linkedClass.isSubClass(defn. Mirror_SumClass )
127- )
119+ && ! self.is(Scala2x )
120+ && (
121+ // If the sum type is compiled from source, and `self` is a "generic sum"
122+ // then its companion object will become a sum mirror in `posttyper`. (This method
123+ // can be called from `typer` when summoning a Mirror.)
124+ // However if `self` is from a binary file, then we should check that its companion
125+ // subclasses `Mirror.Sum`. e.g. before Scala 3.1, hierarchical sum types were not
126+ // considered "generic sums", so their companion would not cache the mirror.
127+ // Companions from TASTy will already be typed as `Mirror.Sum`.
128+ self.isDefinedInSource || companionExtendsSum
129+ )
128130
129131 /** Is this a sealed class or trait for which a sum mirror is generated?
130132 * It must satisfy the following conditions:
0 commit comments