bug icon indicating copy to clipboard operation
bug copied to clipboard

-Ycheck reports false positives for existentials in the expected type

Open sjrd opened this issue 8 years ago • 1 comments

Main.scala:

package test

object Main {
  def main(args: Array[String]): Unit = {
    val c: Class[_] = classOf[String]
    println(c)
    foo(classOf[String])
  }

  def foo(c: Class[_]): Unit =
    println(c)
}

Invocation:

$ ~/opt/scala-2.12.3/bin/scalac -Ycheck:typer,tailcalls Main.scala 
[Now checking: typer]
warning: [check: typer]
Out of scope symbol reference {
      tree  ValDef               val c: Class[_] = classOf[java.lang.String]
  position  RangePosition        Main.scala:5
  with sym  TermSymbol           val c: Class[_]                              in  method main -> object Main -> package test
   encl(1)  MethodSymbol         def main(args: Array[String]): Unit          in  object Main -> package test
   encl(2)  ModuleSymbol         object Main                                  in  package test
    ref to  AbstractTypeSymbol   _$1 (<deferred> <existential>)               in  value c -> method main -> object Main -> package test
}
warning: [check: typer]
Out of scope symbol reference {
      tree  Ident                c
  position  OffsetPosition       Main.scala:6
  with sym  TermSymbol           val c: Class[_]                      in  method main -> object Main -> package test
   and tpe  AliasArgsTypeRef     Class[_$1]
   encl(1)  MethodSymbol         def main(args: Array[String]): Unit  in  object Main -> package test
   encl(2)  ModuleSymbol         object Main                          in  package test
    ref to  AbstractTypeSymbol   _$1 (<deferred> <existential>)       in  value c -> method main -> object Main -> package test
}
warning: [check: typer]
Out of scope symbol reference {
      tree  Apply                Main.this.foo(classOf[java.lang.String])
  position  OffsetPosition       Main.scala:7
  with sym  MethodSymbol         def foo(c: Class[_]): Unit                in  object Main -> package test
   and tpe  ClassNoArgsTypeRef   Unit
   encl(1)  MethodSymbol         def main(args: Array[String]): Unit       in  object Main -> package test
   encl(2)  ModuleSymbol         object Main                               in  package test
    ref to  AbstractTypeSymbol   _$2 (<deferred> <existential>)            in  value c -> method foo -> object Main -> package test
}
warning: [check: typer]
Out of scope symbol reference {
      tree  Select               Main.this.foo
  position  OffsetPosition       Main.scala:7
  with sym  MethodSymbol         def foo(c: Class[_]): Unit           in  object Main -> package test
   and tpe  MethodType           (c: Class[_])Unit
   encl(1)  MethodSymbol         def main(args: Array[String]): Unit  in  object Main -> package test
   encl(2)  ModuleSymbol         object Main                          in  package test
    ref to  AbstractTypeSymbol   _$2 (<deferred> <existential>)       in  value c -> method foo -> object Main -> package test
}
warning: [check: typer]
Out of scope symbol reference {
      tree  DefDef               def foo(c: Class[_]): Unit = scala.Predef.println(c)
  position  OffsetPosition       Main.scala:10
  with sym  MethodSymbol         def foo(c: Class[_]): Unit                            in  object Main -> package test
   encl(1)  ModuleSymbol         object Main                                           in  package test
    ref to  AbstractTypeSymbol   _$2 (<deferred> <existential>)                        in  value c -> method foo -> object Main -> package test
}
warning: [check: typer]
Out of scope symbol reference {
      tree  ValDef               val c: Class[_] = _
  position  OffsetPosition       Main.scala:10
  with sym  TermSymbol           c: Class[_]                     in  method foo -> object Main -> package test
   encl(1)  MethodSymbol         def foo(c: Class[_]): Unit      in  object Main -> package test
   encl(2)  ModuleSymbol         object Main                     in  package test
    ref to  AbstractTypeSymbol   _$2 (<deferred> <existential>)  in  value c -> method foo -> object Main -> package test
}
warning: [check: typer]
Out of scope symbol reference {
      tree  Ident                c
  position  OffsetPosition       Main.scala:11
  with sym  TermSymbol           c: Class[_]                     in  method foo -> object Main -> package test
   and tpe  AliasArgsTypeRef     Class[_$2]
   encl(1)  MethodSymbol         def foo(c: Class[_]): Unit      in  object Main -> package test
   encl(2)  ModuleSymbol         object Main                     in  package test
    ref to  AbstractTypeSymbol   _$2 (<deferred> <existential>)  in  value c -> method foo -> object Main -> package test
}
[Now checking: tailcalls]
warning: [check: tailcalls]
Out of scope symbol reference {
      tree  Apply                Main.this.foo(classOf[java.lang.String])
  position  OffsetPosition       Main.scala:7
  with sym  MethodSymbol         def foo(c: Class[_]): Unit                in  object Main -> package test
   and tpe  ClassNoArgsTypeRef   Unit
   encl(1)  MethodSymbol         def main(args: Array[String]): Unit       in  object Main -> package test
   encl(2)  ModuleClassSymbol    Main: test.Main.type                      in  package test
    ref to  AbstractTypeSymbol   _$2 (<deferred> <existential>)            in  value c -> method foo -> object Main -> package test
}
warning: [check: tailcalls]
Out of scope symbol reference {
      tree  Select               Main.this.foo
  position  OffsetPosition       Main.scala:7
  with sym  MethodSymbol         def foo(c: Class[_]): Unit           in  object Main -> package test
   and tpe  MethodType           (c: Class[_])Unit
   encl(1)  MethodSymbol         def main(args: Array[String]): Unit  in  object Main -> package test
   encl(2)  ModuleClassSymbol    Main: test.Main.type                 in  package test
    ref to  AbstractTypeSymbol   _$2 (<deferred> <existential>)       in  value c -> method foo -> object Main -> package test
}
warning: [check: tailcalls]
Out of scope symbol reference {
      tree  DefDef               def foo(c: Class[_]): Unit = scala.Predef.println(c)
  position  OffsetPosition       Main.scala:10
  with sym  MethodSymbol         def foo(c: Class[_]): Unit                            in  object Main -> package test
   encl(1)  ModuleClassSymbol    Main: test.Main.type                                  in  package test
    ref to  AbstractTypeSymbol   _$2 (<deferred> <existential>)                        in  value c -> method foo -> object Main -> package test
}
10 warnings found

The same issue can be reproduced, among others, with 2.12.4, 2.11.8, 2.11.11, and 2.10.6 (the latter with less verbose messages, but same error it seems).

sjrd avatar Oct 25 '17 09:10 sjrd