@@ -87,22 +87,28 @@ object SymUtils:
87
87
88
88
def isGenericProduct (using Context ): Boolean = whyNotGenericProduct.isEmpty
89
89
90
+ def useCompanionAsMirror (using Context ): Boolean = self.linkedClass.exists && ! self.is(Scala2x )
91
+
90
92
/** Is this a sealed class or trait for which a sum mirror is generated?
91
93
* It must satisfy the following conditions:
92
94
* - it has at least one child class or object
93
95
* - none of its children are anonymous classes
94
96
* - all of its children are addressable through a path from the parent class
97
+ * and also the location of the generated mirror.
95
98
* - all of its children are generic products or singletons
96
99
*/
97
- def whyNotGenericSum (using Context ): String =
100
+ def whyNotGenericSum (declScope : Symbol )( using Context ): String =
98
101
if (! self.is(Sealed ))
99
102
s " it is not a sealed ${self.kindString}"
100
103
else {
101
104
val children = self.children
105
+ val companionMirror = self.useCompanionAsMirror
106
+ assert(! (companionMirror && (declScope ne self.linkedClass)))
102
107
def problem (child : Symbol ) = {
103
108
104
109
def isAccessible (sym : Symbol ): Boolean =
105
- self.isContainedIn(sym) || sym.is(Module ) && isAccessible(sym.owner)
110
+ (self.isContainedIn(sym) && (companionMirror || declScope.isContainedIn(sym)))
111
+ || sym.is(Module ) && isAccessible(sym.owner)
106
112
107
113
if (child == self) " it has anonymous or inaccessible subclasses"
108
114
else if (! isAccessible(child.owner)) i " its child $child is not accessible "
@@ -117,7 +123,7 @@ object SymUtils:
117
123
else children.map(problem).find(! _.isEmpty).getOrElse(" " )
118
124
}
119
125
120
- def isGenericSum (using Context ): Boolean = whyNotGenericSum.isEmpty
126
+ def isGenericSum (declScope : Symbol )( using Context ): Boolean = whyNotGenericSum(declScope) .isEmpty
121
127
122
128
/** If this is a constructor, its owner: otherwise this. */
123
129
final def skipConstructor (using Context ): Symbol =
0 commit comments