Skip to content

Fix error message when deriving an obstract type #13812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2021
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
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