Skip to content

NoType when deriving an abstract type #13808

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

Closed
bertlebee opened this issue Oct 25, 2021 · 5 comments · Fixed by #13812
Closed

NoType when deriving an abstract type #13808

bertlebee opened this issue Oct 25, 2021 · 5 comments · Fixed by #13812
Assignees
Milestone

Comments

@bertlebee
Copy link

bertlebee commented Oct 25, 2021

Compiler version

3.1.0

Minimized code

object OpaqueTypes:
  opaque type OpaqueType[A] = List[A]
  object OpaqueType:
    def derived[A]: OpaqueType[A] = Nil

import OpaqueTypes.OpaqueType
case class Boom[A](value: A) derives OpaqueType

Output

-- Error: foo.scala:7:37 -------------------------------------------------------
7 |case class Boom[A](value: A) derives OpaqueType
  |                                     ^^^^^^^^^^
  |                                     <notype> is not a class type
1 error found

Expectation

compiles or provides more a useful error

In case it's not clear from the code, I'm trying to derive an instance of an opaque type.

@bishabosha
Copy link
Member

I have updated the code with the error shown in scala 3.1

@bishabosha
Copy link
Member

bishabosha commented Oct 25, 2021

minimised to being a plain abstract type:

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

import FooModule.Foo
case class Boom[A](value: A) derives Foo

@bishabosha bishabosha changed the title error deriving instances of opaque types NoType when deriving an abstract type Oct 25, 2021
@odersky odersky self-assigned this Oct 25, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Oct 25, 2021
@bertlebee
Copy link
Author

bertlebee commented Oct 25, 2021

Wow, thanks for the quick response and fix! I take it from the new error message we're unable to use the derivation functionality with opaque types, so I'll have to use a wrapper type instead. Is there a reason this is unsound or is it just not possible?

@odersky
Copy link
Contributor

odersky commented Oct 26, 2021

Nobody has thought through the ramifications of allowing something different than a class type. Also it would be irregular wrt to extends which also requires classes.

@bertlebee
Copy link
Author

bertlebee commented Oct 26, 2021

Thanks for the explanation. This is way above my pay grade so I'll create a feature request and leave it for more brilliant minds to decide if it's sound and worth implementing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants