Skip to content

Commit a87f8bc

Browse files
committed
Fix error message when deriving an obstract type
Fixes #13808
1 parent 29f0374 commit a87f8bc

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Deriving.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ trait Deriving {
8383
*/
8484
private def processDerivedInstance(derived: untpd.Tree): Unit = {
8585
val originalTypeClassType = typedAheadType(derived, AnyTypeConstructorProto).tpe
86-
val typeClassType = checkClassType(underlyingClassRef(originalTypeClassType), derived.srcPos, traitReq = false, stablePrefixReq = true)
86+
val underlyingClassType = underlyingClassRef(originalTypeClassType)
87+
val typeClassType = checkClassType(
88+
underlyingClassType.orElse(originalTypeClassType),
89+
derived.srcPos, traitReq = false, stablePrefixReq = true)
8790
val typeClass = typeClassType.classSymbol
8891
val typeClassParams = typeClass.typeParams
8992
val typeClassArity = typeClassParams.length

tests/neg/i13808.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/neg/i13808.scala:13:37 ---------------------------------------------------------------------------------
2+
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
3+
| ^^^^^^^^^^
4+
| OpaqueTypes.OpaqueType is not a class type
5+
-- Error: tests/neg/i13808.scala:13:49 ---------------------------------------------------------------------------------
6+
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
7+
| ^^^
8+
| FooModule.Foo is not a class type

tests/neg/i13808.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object OpaqueTypes:
2+
opaque type OpaqueType[A] = List[A]
3+
object OpaqueType:
4+
def derived[A]: OpaqueType[A] = Nil
5+
6+
object FooModule:
7+
type Foo[A]
8+
object Foo:
9+
def derived[A]: Foo[A] = Nil.asInstanceOf[Foo[A]]
10+
11+
import FooModule.Foo
12+
import OpaqueTypes.OpaqueType
13+
case class Boom[A](value: A) derives OpaqueType, Foo // error // error
14+

0 commit comments

Comments
 (0)