Skip to content

Crash with named parameters and context function #8881

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
rcano opened this issue May 5, 2020 · 1 comment · Fixed by #8918
Closed

Crash with named parameters and context function #8881

rcano opened this issue May 5, 2020 · 1 comment · Fixed by #8918

Comments

@rcano
Copy link

rcano commented May 5, 2020

Minimized code

object Crash {
  trait Context
  object Label {
    def apply(
      text: String = "UnsetParam",
      tooltip: String = "UnsetParam",
      foo: Int = 0
    ): Context ?=> String = "" //return type needs to be a Context function or it wont trigger
  }
  def update[R](f: Context ?=> R): R = ???
  update {
    //this should blow up
    Label(
      tooltip = "some tooltip",
      text = "someText",
    )
  }
}

Output (click arrow to expand)

## Exception when compiling 4 sources to /tmp/testdotty/target/scala-0.25/classes
scala.MatchError: tree {
  val foo$1: Int = Test.Label.apply$default$3
  Test.Label.apply("someText", "some tooltip", foo$1)
}.apply(evidence$2) has unexpected type of function {
  val foo$1: Int = Test.Label.apply$default$3
  Test.Label.apply("someText", "some tooltip", foo$1)
}.apply/{
  val foo$1: Int = Test.Label.apply$default$3()
  {
    def $anonfun(x$0: Test.Context): String = 
      Test.Label.apply("someText", "some tooltip", foo$1, x$0)
    closure($anonfun)
  }
}: Function1, was (using x$0: Test.Context): String, args = List(Ident(evidence$2)) (of class java.lang.String)
dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:788)
dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2345)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:854)
dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2353)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1867)
dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:866)
dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2322)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2477)
dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:849)
dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:853)
dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2353)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
dotty.tools.dotc.transform.Erasure$Typer.$anonfun$4(Erasure.scala:765)
dotty.tools.dotc.core.Decorators$ListDecorator$.zipWithConserve$extension(Decorators.scala:110)
dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:765)
dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2345)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2500)
dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2003)
dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2333)
dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2337)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2477)
dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2129)
dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2376)
dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
dotty.tools.dotc.transform.Erasure.run(Erasure.scala:121)
dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:318)
scala.collection.immutable.List.map(List.scala:250)
dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:319)
dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:165)
dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
dotty.tools.dotc.Run.runPhases$5(Run.scala:175)
dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:183)
dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
dotty.tools.dotc.Run.compileUnits(Run.scala:190)
dotty.tools.dotc.Run.compileSources(Run.scala:127)
dotty.tools.dotc.Run.compile(Run.scala:110)
dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
dotty.tools.dotc.Driver.process(Driver.scala:194)
dotty.tools.dotc.Main.process(Main.scala)
xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:69)
xsbt.CompilerInterface.run(CompilerInterface.java:41)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.base/java.lang.reflect.Method.invoke(Method.java:566)
sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:248)
sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:122)
sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:95)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:91)
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:186)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3(MixedAnalyzingCompiler.scala:82)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3$adapted(MixedAnalyzingCompiler.scala:77)
sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:215)
sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:77)
sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:146)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:343)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:343)
sbt.internal.inc.Incremental$.doCompile(Incremental.scala:120)
sbt.internal.inc.Incremental$.$anonfun$compile$4(Incremental.scala:100)
sbt.internal.inc.IncrementalCommon.recompileClasses(IncrementalCommon.scala:180)
sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:98)
sbt.internal.inc.Incremental$.$anonfun$compile$3(Incremental.scala:102)
sbt.internal.inc.Incremental$.manageClassfiles(Incremental.scala:155)
sbt.internal.inc.Incremental$.compile(Incremental.scala:92)
sbt.internal.inc.IncrementalCompile$.apply(Compile.scala:75)
sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:348)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:301)
sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:168)
sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:248)
sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:74)
sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:1765)
sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:1738)
scala.Function1.$anonfun$compose$1(Function1.scala:49)
sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
sbt.std.Transform$$anon$4.work(Transform.scala:67)
sbt.Execute.$anonfun$submit$2(Execute.scala:281)
sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
sbt.Execute.work(Execute.scala:290)
sbt.Execute.$anonfun$submit$1(Execute.scala:281)
sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:834)
           
stack trace is suppressed; run last Compile / compileIncremental for the full output
(Compile / compileIncremental) scala.MatchError: tree {
  val foo$1: Int = Test.Label.apply$default$3
  Test.Label.apply("someText", "some tooltip", foo$1)
}.apply(evidence$2) has unexpected type of function {
  val foo$1: Int = Test.Label.apply$default$3
  Test.Label.apply("someText", "some tooltip", foo$1)
}.apply/{
  val foo$1: Int = Test.Label.apply$default$3()
  {
    def $anonfun(x$0: Test.Context): String = 
      Test.Label.apply("someText", "some tooltip", foo$1, x$0)
    closure($anonfun)
  }
}: Function1, was (using x$0: Test.Context): String, args = List(Ident(evidence$2)) (of class java.lang.String)

Note

if the named parameters are passed in the same order as declared, it works

@nicolasstucki
Copy link
Contributor

Minimized to

object Crash {
  def apply(a: String, b: String, c: Int = 0): Int ?=> String = ""
  given Int = ???
  apply(b = "b", a = "a")
}

odersky added a commit to dotty-staging/dotty that referenced this issue May 8, 2020
This is needed to correctly deal with bunched arguments arisign from IFTs.
It's necessary in particular for let-bindings introduced by the compiler,
e.g. when passing default araguments. User-defined blocks are not the
problem since they get already eta expanded in typer.
@nicolasstucki nicolasstucki linked a pull request May 11, 2020 that will close this issue
odersky added a commit that referenced this issue May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants