scala / bug

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

ToolBox.typecheck throws assertion error on overridden method #10189

Open scabug opened 7 years ago

scabug commented 7 years ago

ToolBox.typecheck fails an assertion with the message "import failure: cannot determine unique overloaded method alternative from..." when typechecking an overridden interface method.

import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox

val toolBox = currentMirror.mkToolBox()

// the expression prints fine in scala/scalac
println(java.time.Instant.now().plus(24, java.time.temporal.ChronoUnit.HOURS))

val tree = toolBox.parse("""
  java.time.Instant.now().plus(24, java.time.temporal.ChronoUnit.HOURS)
""")

toolBox.typecheck(tree) // throws AssertionError

Stack trace:

java.lang.AssertionError: assertion failed: import failure: cannot determine unique overloaded method alternative from
 def plus(x$1: Long,x$2: java.time.temporal.TemporalUnit): java.time.temporal.Temporal
def plus(x$1: Long,x$2: java.time.temporal.TemporalUnit): java.time.Instant
 that matches method plus:(x$1: Long, x$2: java.time.temporal.TemporalUnit)java.time.Instant
  at scala.reflect.internal.Importers$StandardImporter.disambiguate$1(Importers.scala:183)
  at scala.reflect.internal.Importers$StandardImporter.recreateOrRelink$1(Importers.scala:188)
  at scala.reflect.internal.Importers$StandardImporter.importSymbol(Importers.scala:210)
  at scala.reflect.internal.Importers$StandardImporter.recreatedTreeCompleter(Importers.scala:298)
  at scala.reflect.internal.Importers$StandardImporter.$anonfun$importTree$1(Importers.scala:417)
  at scala.reflect.internal.Importers$StandardImporter.tryFixup(Importers.scala:49)
  at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:418)
  at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:374)
  at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:415)
  at scala.reflect.internal.Importers$StandardImporter.importTree(Importers.scala:29)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.$anonfun$typecheck$6(ToolBoxFactory.scala:380)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.apply(ToolBoxFactory.scala:359)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.typecheck(ToolBoxFactory.scala:371)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.typecheck(ToolBoxFactory.scala:26)
  ... 29 elided

Thanks for reading!

scabug commented 7 years ago

Imported From: https://issues.scala-lang.org/browse/SI-10189?orig=1 Reporter: Zach R. D. (zachrd) Affected Versions: 2.11.8, 2.12.1

zach-r-d commented 7 years ago

@adriaanm @xeno-by FWIW, the expression works with compile() and eval(), it's just typecheck() that throws an AssertionError.