newtypes icon indicating copy to clipboard operation
newtypes copied to clipboard

Scala 3 Matchable Trait

Open bpholt opened this issue 2 years ago • 1 comments

Given this scala-cli snippet:

//> using scala 3
//> using option -source:future
//> using dep io.monix::newtypes-core:0.2.3

import monix.newtypes.*

type Foo = Foo.Type
object Foo extends NewtypeWrapped[String]

val foo: Foo = Foo("foo")

@main def main(): Unit =
  foo match
    case Foo(x) =>
      println(x)

Since it includes option -source:future, when this is compiled, it warns

$ scala-cli run matchable.scala 
Compiling project (Scala 3.3.0, JVM)
[warn] ./matchable.scala:14:10
[warn] pattern selector should be an instance of Matchable,,
[warn] but it has unmatchable type Foo instead
[warn]     case Foo(x) =>
[warn]          ^^^^^^
Compiled project (Scala 3.3.0, JVM)
foo

Since it works anyway, I think Matchable should probably be added to the Scala 3 sources, but I'm not exactly sure where. Maybe NewEncoding and NewEncodingK should both extend it? Or maybe a new marker trait should be added to NewWrapped that would then extend Matchable on Scala 3?

I'm happy to make a PR once we have a direction.

bpholt avatar Jul 13 '23 20:07 bpholt

@alexandru do you have any thoughts on this?

bpholt avatar Sep 06 '23 15:09 bpholt