Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Deriving.scala
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,11 @@ trait Deriving {
companionRef(tp.underlying)
}
val resultType = instantiated(sym.info)
val module = untpd.ref(companionRef(resultType)).withSpan(sym.span)
val companion = companionRef(resultType)
val module = untpd.ref(companion).withSpan(sym.span)
val rhs = untpd.Select(module, nme.derived)
typed(rhs, resultType)
if companion.termSymbol.exists then typed(rhs, resultType)
else errorTree(rhs, em"$resultType cannot be derived since ${resultType.typeSymbol} has no companion object")
end typeclassInstance

def syntheticDef(sym: Symbol): Tree = inContext(ctx.fresh.setOwner(sym).setNewScope) {
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i11072.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i11072.scala:3:17 ----------------------------------------------------------------------------------
3 |enum Foo derives Sealed { // error
| ^
| Sealed[Foo] cannot be derived since trait Sealed has no companion object
5 changes: 5 additions & 0 deletions tests/neg/i11072.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait Sealed[A]

enum Foo derives Sealed { // error
case A, B, C
}