Skip to content

Compiler crash (null pointer exception) with implicit dispatch #5311

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
yallop opened this issue Oct 23, 2018 · 1 comment
Closed

Compiler crash (null pointer exception) with implicit dispatch #5311

yallop opened this issue Oct 23, 2018 · 1 comment

Comments

@yallop
Copy link

yallop commented Oct 23, 2018

The following program crashes dotc (from the dotty-0.10.0-RC1 release):

object m {
  trait Foo {
    type T[A]
    def bar : (T[Int] => T[Int]) => T[Int => Int]
  }

  def baz (implicit S: Foo, f : S.T[Int] => S.T[Int]) : S.T[Int => Int] =
    S.bar.apply(f)

  def example(implicit s:Foo) : s.T[Int => Int] = {
    baz((x : s.T[Int]) => x)
  }
}

Here's the output:

exception occurred while typechecking minimal.scala
exception occurred while compiling minimal.scala
Exception in thread "main" java.lang.NullPointerException
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typeOfArg(ProtoTypes.scala:319)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typeOfArg(Applications.scala:706)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typeOfArg(Applications.scala:706)
	at dotty.tools.dotc.typer.Applications$Application.addTyped$2$$anonfun$1(Applications.scala:477)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:62)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:78)
	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:514)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:296)
	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:605)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:703)
	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:763)
	at dotty.tools.dotc.typer.Applications.realApply$4$$anonfun$3(Applications.scala:788)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2058)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:799)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:834)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1882)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1936)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1967)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1979)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2050)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:669)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1889)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1936)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1967)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1979)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2050)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1489)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1869)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1935)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1967)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1979)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1998)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2039)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1593)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1872)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1935)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1967)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1979)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1998)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2039)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1707)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1914)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1936)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1967)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1979)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2050)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:60)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:34)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:64)
	at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$2(FrontEnd.scala:88)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:388)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:88)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:175)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:194)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:187)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:195)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:90)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:202)
	at dotty.tools.dotc.Run.compileSources(Run.scala:137)
	at dotty.tools.dotc.Run.compile(Run.scala:121)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:31)
	at dotty.tools.dotc.Driver.process(Driver.scala:134)
	at dotty.tools.dotc.Driver.process(Driver.scala:103)
	at dotty.tools.dotc.Driver.process(Driver.scala:115)
	at dotty.tools.dotc.Driver.main(Driver.scala:142)
	at dotty.tools.dotc.Main.main(Main.scala)
@odersky
Copy link
Contributor

odersky commented Oct 23, 2018

Thanks for reporting this, Jeremy!

The fix in #5312 now produces the following error:

11 |    baz((x : s.T[Int]) => x)
   |                           ^
   |                           found:    s.T[Int] => s.T[Int]
   |                           required: m.Foo

I see where you are going with this. I agree that it would be nice to have a way to distinguish explicit from implicit applications, so that the example would typecheck. Do you have some ideas what syntax to use for this? We have discussed several variants, but nothing is implemented yet.

odersky added a commit that referenced this issue Oct 24, 2018
Fix #5311: Survive mistyped arguments of parameter dependent method types
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