scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Quickfix unexpected edits in method types with params but inferred result #12860

Closed som-snytt closed 9 months ago

som-snytt commented 9 months ago

Reproduction steps

Scala version: 2.13.12 (head)

import scala.collection.{IntStepper, Stepper}

abstract class Stepper1[A] extends Stepper[A] {
  var hasStep = true
  override def estimateSize = if (hasStep) 1 else 0
  override def characteristics = 0
  override def trySplit() = null
}
trait PrimitiveStepper1[A] extends Stepper1[A] {
  override def spliterator[B >: A] = ???
  override def javaIterator[B >: A] = ???
}

Problem

Using

// scalac: -Xsource:3 -Xlint -quickfix:cat=scala3-migration

diff is not legal code.

diff --git a/test/files/run/stepper.scala b/test/files/run/stepper.scala
index af96c6613f..ac55f52275 100644
--- a/test/files/run/stepper.scala
+++ b/test/files/run/stepper.scala
@@ -8,11 +8,11 @@ abstract class Stepper1[A] extends Stepper[A] {
   var hasStep = true
   override def estimateSize = if (hasStep) 1 else 0
   override def characteristics = 0
-  override def trySplit() = null
+  override def trySplit: Null() = null
 }
 trait PrimitiveStepper1[A] extends Stepper1[A] {
-  override def spliterator[B >: A] = ???
-  override def javaIterator[B >: A] = ???
+  override def spliterator: Nothing[B >: A] = ???
+  override def javaIterator: Nothing[B >: A] = ???
 }
 class IntStepper1(elem: Int) extends Stepper1[Int] with IntStepper with PrimitiveStepper1[Int] {
   override def nextStep() = {

It would be nice if I can apply edits to see the new inferred types, instead of the old inferred types, since I am migrating to 3. That is an alternative to silencing the warnings.

via the forum

SethTisue commented 9 months ago

fyi @lrytz

xuwei-k commented 9 months ago

another example

trait A {
  def f[B, C](c: C): Either[B, C]
}

object A {
  val x = new A {
    def f[B, C](c: C) = Right(c)
  }
}
   val x = new A {
-    def f[B, C](c: C) = Right(c)
+    def f: scala.util.Right[Nothing,C][B, C](c: C) = Right(c)
   }
eed3si9n commented 9 months ago

Given the emerging class of quickfixes errors, maybe we should create a documentation that lists current set of quickfixes that are enabled in the compiler(s) so we can identify which fix can be causing the problem in addition to fixing things.

lrytz commented 9 months ago

Fixed in https://github.com/scala/scala/pull/10559

som-snytt commented 9 months ago

I started a list of behaviors under -Xsource:help, I'll also try -quickfix:help. That is my last idea before sleep.