Skip to content

Commit f5305e7

Browse files
oderskyolsdavis
authored andcommitted
Don't lose paramSyms when unpickling from Scala 2
We could lose them for curried methods since the nested method type was copied in case there was a depencency on a parameter of the first method type. Fixes scala#13238
1 parent 1b54946 commit f5305e7

File tree

8 files changed

+68
-2
lines changed

8 files changed

+68
-2
lines changed

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,12 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
847847
val maker = MethodType.companion(
848848
isImplicit = tag == IMPLICITMETHODtpe || params.nonEmpty && params.head.is(Implicit))
849849
val result = maker.fromSymbols(params, restpe)
850+
result.resType match
851+
case restpe1: MethodType if restpe1 ne restpe =>
852+
val prevResParams = paramsOfMethodType.remove(restpe)
853+
if prevResParams != null then
854+
paramsOfMethodType.put(restpe1, prevResParams)
855+
case _ =>
850856
if params.nonEmpty then paramsOfMethodType.put(result, params)
851857
result
852858
case POLYtpe =>

sbt-test/compilerReporter/i7442/project/Reporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Reporter {
2424

2525
lazy val checkSettings = Seq(
2626
Compile / compile / compilerReporter := reporter,
27-
check := (compile in Compile).failure.map(_ => {
27+
check := (Compile / compile).failure.map(_ => {
2828
println(reporter.problems.toList)
2929
assert(reporter.problems.length == 1)
3030
val problem = reporter.problems.head

sbt-test/compilerReporter/simple/project/Reporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Reporter {
2424

2525
lazy val checkSettings = Seq(
2626
Compile / compile / compilerReporter := reporter,
27-
check := (compile in Compile).failure.map(_ => {
27+
check := (Compile / compile).failure.map(_ => {
2828
val problems = reporter.problems
2929
println(problems.toList)
3030
assert(problems.size == 1)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package app
2+
3+
import lib.*
4+
5+
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
val scala3Version = sys.props("plugin.scalaVersion")
2+
val scala2Version = sys.props("plugin.scala2Version")
3+
4+
lazy val lib = project.in(file("lib"))
5+
.settings(
6+
scalaVersion := scala2Version
7+
)
8+
9+
lazy val app = project.in(file("app"))
10+
.dependsOn(lib)
11+
.settings(Reporter.checkSettings)
12+
.settings(
13+
scalaVersion := scala3Version
14+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package lib
2+
3+
trait Bar
4+
class Foo {
5+
def foo(out: Foo)(implicit bar: Bar): out.type = out
6+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sbt._
2+
import Keys._
3+
import KeyRanks.DTask
4+
5+
object Reporter {
6+
import xsbti.{Reporter, Problem, Position, Severity}
7+
8+
lazy val check = TaskKey[Unit]("check", "Check compilation output")
9+
10+
// compilerReporter is marked private in sbt
11+
lazy val compilerReporter = TaskKey[xsbti.Reporter]("compilerReporter", "Experimental hook to listen (or send) compilation failure messages.", DTask)
12+
13+
lazy val reporter =
14+
new xsbti.Reporter {
15+
private val buffer = collection.mutable.ArrayBuffer.empty[Problem]
16+
def reset(): Unit = buffer.clear()
17+
def hasErrors: Boolean = buffer.exists(_.severity == Severity.Error)
18+
def hasWarnings: Boolean = buffer.exists(_.severity == Severity.Warn)
19+
def printSummary(): Unit = println(problems.mkString(System.lineSeparator))
20+
def problems: Array[Problem] = buffer.toArray
21+
def log(problem: Problem): Unit = buffer.append(problem)
22+
def comment(pos: xsbti.Position, msg: String): Unit = ()
23+
}
24+
25+
lazy val checkSettings = Seq(
26+
Compile / compile / compilerReporter := reporter,
27+
check := (Compile / compile).failure.map(_ => {
28+
val problems = reporter.problems
29+
assert(problems.size == 1, problems.size)
30+
assert(problems.head.position.line.get() == 5, problems.head.position.line)
31+
}).value
32+
)
33+
}

sbt-test/scala2-compat/i13238/test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> lib/compile
2+
> app/check

0 commit comments

Comments
 (0)