Skip to content

crash on compilable code: cannot be cast to dotty.tools.dotc.core.Types$MethodType #3539

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

Closed
helloqirun opened this issue Nov 23, 2017 · 1 comment

Comments

@helloqirun
Copy link

scalac can compile but dotc crashes.

$ dotc -version

Dotty compiler version 0.5.0-bin-SNAPSHOT-git-4fefb64 -- Copyright 2002-2017, LAMP/EPFL

$ cat abc.scala

object Test {
  def main(args: Array[String]): Unit = {
    val i2s = (x: Int) => ""
    assert(asInstanceOf.asInstanceOf[AnyRef => String].apply(null) == "")
    val i2i = (x: Int) => x + 1
    assert(i2i.asInstanceOf[AnyRef => Int].apply(null) == 1)
  }
}

$ dotc abc.scala

-- Error: abc.scala:4:36 -------------------------------------------------------
4 |    assert(asInstanceOf.asInstanceOf[AnyRef => String].apply(null) == "")
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |           class Nothing in package scala does not take type parameters

exception occurred while compiling abc.scala
Exception in thread "main" java.lang.ClassCastException: dotty.tools.dotc.core.Types$$anon$9 cannot be cast to dotty.tools.dotc.core.Types$MethodType
	at dotty.tools.dotc.transform.ElimRepeated.$anonfun$1(ElimRepeated.scala:79)
	at dotty.tools.dotc.core.Periods.atPhase(Periods.scala:26)
	at dotty.tools.dotc.core.Phases.atPhase(Phases.scala:36)
	at dotty.tools.dotc.transform.ElimRepeated.transformApply(ElimRepeated.scala:79)
	at dotty.tools.dotc.transform.MegaPhase.goApply(MegaPhase.scala:576)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:250)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:365)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:211)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:364)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:248)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:365)
	at dotty.tools.dotc.transform.MegaPhase.mapValDef$1(MegaPhase.scala:217)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:221)
<snipped>
@allanrenucci
Copy link
Contributor

There are two issues here:

  1. We cannot compile when scalac can:
class Test {
  asInstanceOf.asInstanceOf[AnyRef => String]
}
-- Error: tests/allan/Test.scala:2:27 ------------------------------------------
2 |  asInstanceOf.asInstanceOf[AnyRef => String]
  |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |  class Nothing in package scala does not take type parameters
one error found
java.lang.RuntimeException: Nonzero exit code returned from runner: 1

Note that if Nothing is not inferred, it compiles: asInstanceOf[Nothing].asInstanceOf[AnyRef => String]

  1. Which then causes a compiler crash:
class Test {
  asInstanceOf.asInstanceOf[AnyRef => String].apply(null)
}
-- Error: tests/allan/Test.scala:2:27 ------------------------------------------
2 |  asInstanceOf.asInstanceOf[AnyRef => String].apply(null)
  |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |  class Nothing in package scala does not take type parameters
exception occurred while compiling tests/allan/Test.scala
Exception in thread "main" java.lang.ClassCastException: dotty.tools.dotc.core.Types$ErrorType$$anon$4 cannot be cast to dotty.tools.dotc.core.Types$MethodType
	at dotty.tools.dotc.transform.ElimRepeated.$anonfun$transformApply$1(ElimRepeated.scala:79)
	at dotty.tools.dotc.core.Periods.atPhase(Periods.scala:26)
	at dotty.tools.dotc.core.Phases.atPhase(Phases.scala:36)
	at dotty.tools.dotc.core.Phases.atPhase$(Phases.scala:35)
	at dotty.tools.dotc.core.Contexts$Context.atPhase(Contexts.scala:67)
	at dotty.tools.dotc.transform.ElimRepeated.transformApply(ElimRepeated.scala:78)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants