Skip to content

Don't lose paramSyms when unpickling from Scala 2 #13665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
2 changes: 1 addition & 1 deletion sbt-test/compilerReporter/i7442/project/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sbt-test/compilerReporter/simple/project/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions sbt-test/scala2-compat/i13238/app/App.scala
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions sbt-test/scala2-compat/i13238/build.sbt
Original file line number Diff line number Diff line change
@@ -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
)
6 changes: 6 additions & 0 deletions sbt-test/scala2-compat/i13238/lib/Lib.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package lib

trait Bar
class Foo {
def foo(out: Foo)(implicit bar: Bar): out.type = out
}
33 changes: 33 additions & 0 deletions sbt-test/scala2-compat/i13238/project/Reporter.scala
Original file line number Diff line number Diff line change
@@ -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
)
}
2 changes: 2 additions & 0 deletions sbt-test/scala2-compat/i13238/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> lib/compile
> app/check