Skip to content

Scala 3 Matchable Trait #102

@bpholt

Description

@bpholt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions