Skip to content
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

By-name on Macro implementation crashes compiler #9802

Closed
b-studios opened this issue Sep 16, 2020 · 0 comments · Fixed by #9811
Closed

By-name on Macro implementation crashes compiler #9802

b-studios opened this issue Sep 16, 2020 · 0 comments · Fixed by #9811

Comments

@b-studios
Copy link
Contributor

Specifying a macro argument as by-name crashes the compiler instead of reporting an error that this is not allowed.

Minimized code

// macro implementation
inline def crash(inline prog: Double): Double = ${impl('prog)}
def impl(prog: => Expr[Double])(using QuoteContext) : Expr[Double] = '{ 42.0 }

// macro call
crash(4)

Output (click arrow to expand)

[error] 10 |  bugs.byname.crash(4)
[error]    |  ^^^^^^^^^^^^^^^^^^^^
[error]    |A runtime exception occurred while executing macro expansion
[error]    |argument type mismatch
[error]    |java.lang.IllegalArgumentException: argument type mismatch
[error]    |	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]    |	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error]    |	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]    |	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error]    |	at dotty.tools.dotc.transform.Splicer$Interpreter.interpretedStaticMethodCall$$anonfun$2$$anonfun$1(Splicer.scala:328)
[error]    |	at dotty.tools.dotc.transform.Splicer$Interpreter.stopIfRuntimeException(Splicer.scala:388)
[error]    |	at dotty.tools.dotc.transform.Splicer$Interpreter.interpretedStaticMethodCall$$anonfun$1(Splicer.scala:328)
[error]    |	at dotty.tools.dotc.transform.Splicer$Interpreter.interpretTree(Splicer.scala:253)
[error]    |	at dotty.tools.dotc.transform.Splicer$Interpreter.interpretTree$$anonfun$4(Splicer.scala:273)
[error]    |	at dotty.tools.dotc.transform.Splicer$.$anonfun$2(Splicer.scala:53)
[error]    |	at scala.Option.fold(Option.scala:263)
[error]    |	at dotty.tools.dotc.transform.Splicer$.splice(Splicer.scala:53)
[error]    |	at dotty.tools.dotc.typer.Inliner.dotty$tools$dotc$typer$Inliner$$expandMacro(Inliner.scala:1413)
[error]    |	at dotty.tools.dotc.typer.Inliner$InlineTyper.typedApply(Inliner.scala:1240)
[error]    |	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2456)
[error]    |	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error]    |	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error]    |	at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error]    |	at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:60)
[error]    |	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2461)
[error]    |	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error]    |	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:122)
[error]    |	at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error]    |	at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2583)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error]    |	at dotty.tools.dotc.typer.Inliner.op$proxy3$1(Inliner.scala:736)
[error]    |	at dotty.tools.dotc.typer.Inliner.inlined(Inliner.scala:752)
[error]    |	at dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:125)
[error]    |	at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$4(Typer.scala:3254)
[error]    |	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3362)
[error]    |	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3586)
[error]    |	at dotty.tools.dotc.typer.Typer.op$proxy25$1(Typer.scala:2917)
[error]    |	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2918)
[error]    |	at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error]    |	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2638)
[error]    |	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2661)
[error]    |	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2118)
[error]    |	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2444)
[error]    |	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2448)
[error]    |	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2516)
[error]    |	at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error]    |	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2612)
[error]    |	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2661)
[error]    |	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2242)
[error]    |	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2488)
[error]    |	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2517)
[error]    |	at dotty.tools.dotc.typer.Typer.op$proxy16$1(Typer.scala:2586)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2587)
[error]    |	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2590)
[error]    |	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2705)
[error]    |	at dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79)
[error]    |	at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84)
[error]    |	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error]    |	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43)
[error]    |	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
[error]    |	at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:120)
[error]    |	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error]    |	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error]    |	at scala.collection.immutable.List.foreach(List.scala:333)
[error]    |	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:120)
[error]    |	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:180)
[error]    |	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error]    |	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error]    |	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error]    |	at dotty.tools.dotc.Run.runPhases$5(Run.scala:190)
[error]    |	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:198)
[error]    |	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error]    |	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
[error]    |	at dotty.tools.dotc.Run.compileUnits(Run.scala:205)
[error]    |	at dotty.tools.dotc.Run.compileSources(Run.scala:142)
[error]    |	at dotty.tools.dotc.Run.compile(Run.scala:124)
[error]    |	at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
[error]    |	at dotty.tools.dotc.Driver.process(Driver.scala:195)
[error]    |	at dotty.tools.dotc.Main.process(Main.scala)
[error]    |	at xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:69)
[error]    |	at xsbt.CompilerInterface.run(CompilerInterface.java:41)
[error]    |	at jdk.internal.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
[error]    |	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]    |	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error]    |	at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:237)
[error]    |	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:111)
[error]    |	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:90)
[error]    |	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3(MixedAnalyzingCompiler.scala:82)
[error]    |	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error]    |	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:133)
[error]    |	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:73)
[error]    |	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:116)
[error]    |	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:307)
[error]    |	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:307)
[error]    |	at sbt.internal.inc.Incremental$.doCompile(Incremental.scala:106)
[error]    |	at sbt.internal.inc.Incremental$.$anonfun$compile$4(Incremental.scala:87)
[error]    |	at sbt.internal.inc.IncrementalCommon.recompileClasses(IncrementalCommon.scala:116)
[error]    |	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:63)
[error]    |	at sbt.internal.inc.Incremental$.$anonfun$compile$3(Incremental.scala:89)
[error]    |	at sbt.internal.inc.Incremental$.manageClassfiles(Incremental.scala:134)
[error]    |	at sbt.internal.inc.Incremental$.compile(Incremental.scala:80)
[error]    |	at sbt.internal.inc.IncrementalCompile$.apply(Compile.scala:67)
[error]    |	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:311)
[error]    |	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:269)
[error]    |	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:159)
[error]    |	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:238)
[error]    |	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:69)
[error]    |	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:1549)
[error]    |	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:1523)
[error]    |	at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]    |	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error]    |	at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]    |	at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]    |	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]    |	at sbt.Execute.work(Execute.scala:278)
[error]    |	at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]    |	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]    |	at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]    |	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]    |	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]    |	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]    |	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]    |	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]    |	at java.base/java.lang.Thread.run(Thread.java:834)
[error]    |
[error]    | This location contains code that was inlined from examples.scala:10
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 17, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 17, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 17, 2020
nicolasstucki added a commit that referenced this issue Sep 17, 2020
Fix #9802: Interpret by-name params as `() => interpret(arg)`
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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