Skip to content

Type mismatch with a + operator in an extension method of a newtype #12960

Closed as not planned
@hmemcpy

Description

@hmemcpy

Scala version: 2.13.13 (under Xsource:3)

The following code, under Xsource:3 with Scala 2.13.13:

  type Point = Point.Type
  object Point {
    type Type <: Any
    def apply(x: Int): Point = x.asInstanceOf[Point]

    implicit final class MyExt(val myInt: Point) extends AnyVal {
      def +(other: Int): Point = ???
    }
  }

  val p = Point(3)
  val p2 = p + 2

Produces the following error:

type mismatch;
 found   : Int(2)
 required: String
    val p2 = p + 2

Problem

The problem started after upgrading to Scala 2.13.13. We use the scala-newtype library, and some of our newtypes that define a + operator started to fail with the error above.
The code snippet is the simplified "expanded" version of the newtype macro that also exhibits the problem:

@newtype case class Point(i: Int)
  def +(other: Int): Point
}

In all previous versions, this code compiled fine under Xsource:3.

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