diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 1a70fb1e9d2d..a04a17bb3689 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -847,6 +847,12 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val maker = MethodType.companion( isImplicit = tag == IMPLICITMETHODtpe || params.nonEmpty && params.head.is(Implicit)) val result = maker.fromSymbols(params, restpe) + result.resType match + case restpe1: MethodType if restpe1 ne restpe => + val prevResParams = paramsOfMethodType.remove(restpe) + if prevResParams != null then + paramsOfMethodType.put(restpe1, prevResParams) + case _ => if params.nonEmpty then paramsOfMethodType.put(result, params) result case POLYtpe => diff --git a/sbt-test/compilerReporter/i7442/project/Reporter.scala b/sbt-test/compilerReporter/i7442/project/Reporter.scala index 1ccf1a8b914b..3df9cd0bdfca 100644 --- a/sbt-test/compilerReporter/i7442/project/Reporter.scala +++ b/sbt-test/compilerReporter/i7442/project/Reporter.scala @@ -24,7 +24,7 @@ object Reporter { lazy val checkSettings = Seq( Compile / compile / compilerReporter := reporter, - check := (compile in Compile).failure.map(_ => { + check := (Compile / compile).failure.map(_ => { println(reporter.problems.toList) assert(reporter.problems.length == 1) val problem = reporter.problems.head diff --git a/sbt-test/compilerReporter/simple/project/Reporter.scala b/sbt-test/compilerReporter/simple/project/Reporter.scala index 632219cd10e2..f67d1ec51d91 100644 --- a/sbt-test/compilerReporter/simple/project/Reporter.scala +++ b/sbt-test/compilerReporter/simple/project/Reporter.scala @@ -24,7 +24,7 @@ object Reporter { lazy val checkSettings = Seq( Compile / compile / compilerReporter := reporter, - check := (compile in Compile).failure.map(_ => { + check := (Compile / compile).failure.map(_ => { val problems = reporter.problems println(problems.toList) assert(problems.size == 1) diff --git a/sbt-test/scala2-compat/i13238/app/App.scala b/sbt-test/scala2-compat/i13238/app/App.scala new file mode 100644 index 000000000000..795c61a2f5e8 --- /dev/null +++ b/sbt-test/scala2-compat/i13238/app/App.scala @@ -0,0 +1,5 @@ +package app + +import lib.* + +def boom(foo: Foo) = foo.foo(foo) // error: no implicit argument of type lib.Bar was found for parameter bar of method foo in class Foo diff --git a/sbt-test/scala2-compat/i13238/build.sbt b/sbt-test/scala2-compat/i13238/build.sbt new file mode 100644 index 000000000000..e927413ece76 --- /dev/null +++ b/sbt-test/scala2-compat/i13238/build.sbt @@ -0,0 +1,14 @@ +val scala3Version = sys.props("plugin.scalaVersion") +val scala2Version = sys.props("plugin.scala2Version") + +lazy val lib = project.in(file("lib")) + .settings( + scalaVersion := scala2Version + ) + +lazy val app = project.in(file("app")) + .dependsOn(lib) + .settings(Reporter.checkSettings) + .settings( + scalaVersion := scala3Version + ) diff --git a/sbt-test/scala2-compat/i13238/lib/Lib.scala b/sbt-test/scala2-compat/i13238/lib/Lib.scala new file mode 100644 index 000000000000..a642f5883141 --- /dev/null +++ b/sbt-test/scala2-compat/i13238/lib/Lib.scala @@ -0,0 +1,6 @@ +package lib + +trait Bar +class Foo { + def foo(out: Foo)(implicit bar: Bar): out.type = out +} diff --git a/sbt-test/scala2-compat/i13238/project/Reporter.scala b/sbt-test/scala2-compat/i13238/project/Reporter.scala new file mode 100644 index 000000000000..1671bf80735f --- /dev/null +++ b/sbt-test/scala2-compat/i13238/project/Reporter.scala @@ -0,0 +1,33 @@ +import sbt._ +import Keys._ +import KeyRanks.DTask + +object Reporter { + import xsbti.{Reporter, Problem, Position, Severity} + + lazy val check = TaskKey[Unit]("check", "Check compilation output") + + // compilerReporter is marked private in sbt + lazy val compilerReporter = TaskKey[xsbti.Reporter]("compilerReporter", "Experimental hook to listen (or send) compilation failure messages.", DTask) + + lazy val reporter = + new xsbti.Reporter { + private val buffer = collection.mutable.ArrayBuffer.empty[Problem] + def reset(): Unit = buffer.clear() + def hasErrors: Boolean = buffer.exists(_.severity == Severity.Error) + def hasWarnings: Boolean = buffer.exists(_.severity == Severity.Warn) + def printSummary(): Unit = println(problems.mkString(System.lineSeparator)) + def problems: Array[Problem] = buffer.toArray + def log(problem: Problem): Unit = buffer.append(problem) + def comment(pos: xsbti.Position, msg: String): Unit = () + } + + lazy val checkSettings = Seq( + Compile / compile / compilerReporter := reporter, + check := (Compile / compile).failure.map(_ => { + val problems = reporter.problems + assert(problems.size == 1, problems.size) + assert(problems.head.position.line.get() == 5, problems.head.position.line) + }).value + ) +} diff --git a/sbt-test/scala2-compat/i13238/test b/sbt-test/scala2-compat/i13238/test new file mode 100644 index 000000000000..b75c1ced2bbb --- /dev/null +++ b/sbt-test/scala2-compat/i13238/test @@ -0,0 +1,2 @@ +> lib/compile +> app/check