Skip to content
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

Any wrongly inferred and fails to warn #12852

Open
som-snytt opened this issue Aug 26, 2023 · 0 comments
Open

Any wrongly inferred and fails to warn #12852

som-snytt opened this issue Aug 26, 2023 · 0 comments
Labels
errors and warnings fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) typer
Milestone

Comments

@som-snytt
Copy link

Reproduction steps

Scala version: 2.13.11

//positioned.getAndRemoveAttachment[NamePos].foreach(att => ts.head.updateAttachment[NamePos](att))
//positioned.getAndRemoveAttachment[NamePos].foreach(ts.head.updateAttachment) // infers Any

import reflect.ClassTag

class C {
  def f[A: ClassTag]: Option[A] = None
  def g[A: ClassTag](a: A): this.type = this
}

class D {
  val c = new C
  def d(): Unit = {
    c.f[String].foreach(c.g)
  }
}

Problem

Per title.

➜  scalac -Vprint -Xlint eta-infer.scala
[[syntax trees at end of                     typer]] // eta-infer.scala
package <empty> {
  import scala.reflect.ClassTag;
  class C extends scala.AnyRef {
    def <init>(): C = {
      C.super.<init>();
      ()
    };
    def f[A](implicit evidence$1: scala.reflect.ClassTag[A]): Option[A] = scala.None;
    def g[A](a: A)(implicit evidence$2: scala.reflect.ClassTag[A]): C.this.type = this
  };
  class D extends scala.AnyRef {
    def <init>(): D = {
      D.super.<init>();
      ()
    };
    private[this] val c: C = new C();
    <stable> <accessor> def c: C = D.this.c;
    def d(): Unit = D.this.c.f[String]((ClassTag.apply[String](classOf[java.lang.String]): scala.reflect.ClassTag[String])).foreach[C](((a: Any) => D.this.c.g[Any](a)((ClassTag.Any: scala.reflect.ClassTag[Any]))))
  }
}

Scala 3 does not infer Any:

➜  scalac -Vprint:refchecks eta-infer.scala
[[syntax trees at end of MegaPhase{firstTransform, checkReentrant, elimPackagePrefixes, cookComments, checkStatic, checkLoopingImplicits, betaReduce, inlineVals, expandSAMs, elimRepeated, refchecks}]] // eta-infer.scala
package <empty> {
  import reflect.ClassTag
  @SourceFile("eta-infer.scala") class C() extends Object() {
    def f[A](implicit evidence$1: reflect.ClassTag[A]): Option[A] = None
    def g[A](a: A)(implicit evidence$2: reflect.ClassTag[A]): (C.this : C) = this
  }
  @SourceFile("eta-infer.scala") class D() extends Object() {
    val c: C = new C()
    def d(): Unit =
      {
        this.c.f[String](scala.reflect.ClassTag.apply[String](classOf[String])).foreach[C](
          {
            def $anonfun(a: String): C = this.c.g[String](a)(scala.reflect.ClassTag.apply[String](classOf[String]))
            closure($anonfun)
          }
        )
      }
  }
}
@som-snytt som-snytt added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Aug 26, 2023
@SethTisue SethTisue added this to the Backlog milestone Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors and warnings fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) typer
Projects
None yet
Development

No branches or pull requests

2 participants