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