Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,18 @@ object SymUtils:
* It must satisfy the following conditions:
* - it has at least one child class or object
* - none of its children are anonymous classes
* - all of its children are addressable through a path from its companion object
* - all of its children are addressable through a path from the parent class
* - all of its children are generic products or singletons
*/
def whyNotGenericSum(using Context): String =
if (!self.is(Sealed))
s"it is not a sealed ${self.kindString}"
else {
val children = self.children
val companion = self.linkedClass
def problem(child: Symbol) = {

def isAccessible(sym: Symbol): Boolean =
companion.isContainedIn(sym) || sym.is(Module) && isAccessible(sym.owner)
self.isContainedIn(sym) || sym.is(Module) && isAccessible(sym.owner)

if (child == self) "it has anonymous or inaccessible subclasses"
else if (!isAccessible(child.owner)) i"its child $child is not accessible"
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i10997.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sealed trait Parent

trait Wrapper {

case class Foo(x: Int, y: Int, s: String) extends Parent
case class Bar(x: Int, y: Int) extends Parent

println(summon[deriving.Mirror.Of[Parent]]) // error
}
24 changes: 24 additions & 0 deletions tests/pos/i10997.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Test {

sealed trait Parent
case class Foo(x: Int, y: Int, s: String) extends Parent
case class Bar(x: Int, y: Int) extends Parent

println(summon[deriving.Mirror.Of[Parent]])
}

object Test2 {

case class Foo(x: Int, y: Int, s: String) extends i.Parent
case class Bar(x: Int, y: Int) extends i.Parent

val i = Inner()

class Inner {

sealed trait Parent

println(summon[deriving.Mirror.Of[Parent]])
}

}
2 changes: 1 addition & 1 deletion tests/run/deriving-constructor-order.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Test extends App {
case _: T => ()
}

sealed trait Base1
sealed trait Base1 // Base1 MUST NOT have a companion here!
case class Foo() extends Base1
case object Bar extends Base1
case class Qux(i: Int) extends Base1
Expand Down
2 changes: 1 addition & 1 deletion tests/run/deriving.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object T
case class A(x: Int, y: Int) extends T
case object B extends T

sealed trait U
sealed trait U // U MUST NOT have a companion here!
case class C() extends U

object Test extends App {
Expand Down