Skip to content

Compiler option -Vtype-diffs leads to error type information lost in some case. #12561

@counter2015

Description

@counter2015

Reproduction steps

Scala version: 2.13.8

The build.sbt

ThisBuild / version := "0.1.0"

ThisBuild / scalaVersion := "2.13.8"


lazy val root = (project in file("."))
  .settings(
    name := "demo"
  )
  .aggregate(
    project1
  )

lazy val project1 =
  (project in file("project1"))
    .settings(
      commonSettings("project1"),
      libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.32"
    )



def commonSettings(module: String, languageVersion: String = "2.13.8") = {
  Seq[Setting[_]](
    name              := s"demo-$module",
    scalaVersion      := languageVersion,
    scalacOptions ++= Seq(
      "-Vtype-diffs",
    ),
    fork := true
  )
}

The code

import akka.actor.ActorSystem

import scala.concurrent.duration._

object BugExample {

  def main(args: Array[String]): Unit = {
    val system = ActorSystem("test")
    implicit val ec = system.dispatcher

    system.scheduler.schedule(1.second, 10.seconds, () => println("why cant convert this to Runnable"))
  }

}

Problem

When compile above code, the type information is lost in error.

BugExample.scala:11:56: type mismatch;
[error]   () => scala.Unit
[error]     system.scheduler.schedule(1.second, 10.seconds, () => println("why cant convert this to Runnable"))
[error]                                                        ^
[error] one error found
[error] (project1 / Compile / compileIncremental) Compilation failed

It should be

BugExample.scala:11:56: type mismatch;
[error]  found   : () => Unit
[error]  required: Runnable
[error]         system.scheduler.schedule(1.second, 10.seconds, () => println("why cant convert this to Runnable"))

see also #12560

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions