Skip to content

Commit

Permalink
Merge pull request scala#13812 from dotty-staging/fix-13808
Browse files Browse the repository at this point in the history
Fix error message when deriving an obstract type
  • Loading branch information
bishabosha authored Oct 25, 2021
2 parents 4382930 + a87f8bc commit 968dd1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Deriving.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ trait Deriving {
*/
private def processDerivedInstance(derived: untpd.Tree): Unit = {
val originalTypeClassType = typedAheadType(derived, AnyTypeConstructorProto).tpe
val typeClassType = checkClassType(underlyingClassRef(originalTypeClassType), derived.srcPos, traitReq = false, stablePrefixReq = true)
val underlyingClassType = underlyingClassRef(originalTypeClassType)
val typeClassType = checkClassType(
underlyingClassType.orElse(originalTypeClassType),
derived.srcPos, traitReq = false, stablePrefixReq = true)
val typeClass = typeClassType.classSymbol
val typeClassParams = typeClass.typeParams
val typeClassArity = typeClassParams.length
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i13808.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Error: tests/neg/i13808.scala:13:37 ---------------------------------------------------------------------------------
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
| ^^^^^^^^^^
| OpaqueTypes.OpaqueType is not a class type
-- Error: tests/neg/i13808.scala:13:49 ---------------------------------------------------------------------------------
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
| ^^^
| FooModule.Foo is not a class type
14 changes: 14 additions & 0 deletions tests/neg/i13808.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object OpaqueTypes:
opaque type OpaqueType[A] = List[A]
object OpaqueType:
def derived[A]: OpaqueType[A] = Nil

object FooModule:
type Foo[A]
object Foo:
def derived[A]: Foo[A] = Nil.asInstanceOf[Foo[A]]

import FooModule.Foo
import OpaqueTypes.OpaqueType
case class Boom[A](value: A) derives OpaqueType, Foo // error // error

0 comments on commit 968dd1b

Please sign in to comment.