Skip to content

Expr pattern match throws java.lang.VerifyError: Bad local variable type #14696

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
xuwei-k opened this issue Mar 16, 2022 · 2 comments · Fixed by #15073
Closed

Expr pattern match throws java.lang.VerifyError: Bad local variable type #14696

xuwei-k opened this issue Mar 16, 2022 · 2 comments · Fixed by #15073
Assignees
Labels
Milestone

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Mar 16, 2022

Compiler version

  • 3.1.1
  • 3.1.2-RC2
  • 3.2.0-RC1-bin-20220308-29073f1-NIGHTLY

Minimized code

build.sbt

scalaVersion := "3.1.2-RC2"

src/main/scala/Macros.scala

package example

import scala.quoted.*

object Macros {
  def fooImpl(a: Expr[Any])(using Quotes): Expr[Any] = a match {
    case '{ $x1: String } | '{ $x2: Int } =>
      println((x1, x2))
      a
  }

  inline def foo(a: Any) = ${fooImpl('a)}
}

src/test/scala/Test.scala

package example

object Test {
  def main(args: Array[String]): Unit = Macros.foo(3)
}

sbt Test/run

Output (click arrow to expand)

java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    example/Macros$.fooImpl(Lscala/quoted/Expr;Lscala/quoted/Quotes;)Lscala/quoted/Expr; @179: aload
  Reason:
    Type top (current frame, locals[8]) is not assignable to reference type
  Current Frame:
    bci: @179
    flags: { }
    locals: { 'example/Macros$', 'scala/quoted/Expr', 'scala/quoted/Quotes', 'scala/quoted/Expr', 'scala/Option' }
    stack: { 'scala/Predef$', 'scala/Tuple2$' }
  Bytecode:
    0x0000000: 2b4e 2dc6 00a7 2cc0 000b b900 2701 002d
    0x0000010: 2cc0 0029 122b 0101 b900 2f04 00b9 0033
    0x0000020: 0300 3a04 1904 b600 399a 002f 1904 b600
    0x0000030: 3cc0 003e 3a05 1905 3a06 1906 c600 1c19
    0x0000040: 06b6 0041 c000 433a 0719 07c1 0043 9900
    0x0000050: 0a19 073a 08a7 0058 2cc0 000b b900 2701
    0x0000060: 002d 2cc0 0029 1245 0101 b900 2f04 00b9
    0x0000070: 0033 0300 3a09 1909 b600 399a 002f 1909
    0x0000080: b600 3cc0 003e 3a0a 190a 3a0b 190b c600
    0x0000090: 1c19 0bb6 0041 c000 433a 0c19 0cc1 0043
    0x00000a0: 9900 0a19 0c3a 0da7 0006 a700 17b2 004a
    0x00000b0: b200 4f19 0819 0db6 0053 b600 572b a700
    0x00000c0: 0cbb 0059 592d b700 5bbf b0            
  Stackmap Table:
    append_frame(@88,Object[#67],Object[#53])
    chop_frame(@170,1)
    append_frame(@173,Object[#53])
    chop_frame(@193,1)
    full_frame(@202,{Object[#2],Object[#67],Object[#97],Object[#67],Object[#53]},{Object[#67]})
 while compiling /Users/kenji/aaa/src/test/scala/Test.scala
[error] ## Exception when compiling 1 sources to /Users/kenji/aaa/target/scala-3.1.2-RC2/test-classes
[error] java.lang.VerifyError: Bad local variable type
[error] Exception Details:
[error]   Location:
[error]     example/Macros$.fooImpl(Lscala/quoted/Expr;Lscala/quoted/Quotes;)Lscala/quoted/Expr; @179: aload
[error]   Reason:
[error]     Type top (current frame, locals[8]) is not assignable to reference type
[error]   Current Frame:
[error]     bci: @179
[error]     flags: { }
[error]     locals: { 'example/Macros$', 'scala/quoted/Expr', 'scala/quoted/Quotes', 'scala/quoted/Expr', 'scala/Option' }
[error]     stack: { 'scala/Predef$', 'scala/Tuple2$' }
[error]   Bytecode:
[error]     0x0000000: 2b4e 2dc6 00a7 2cc0 000b b900 2701 002d
[error]     0x0000010: 2cc0 0029 122b 0101 b900 2f04 00b9 0033
[error]     0x0000020: 0300 3a04 1904 b600 399a 002f 1904 b600
[error]     0x0000030: 3cc0 003e 3a05 1905 3a06 1906 c600 1c19
[error]     0x0000040: 06b6 0041 c000 433a 0719 07c1 0043 9900
[error]     0x0000050: 0a19 073a 08a7 0058 2cc0 000b b900 2701
[error]     0x0000060: 002d 2cc0 0029 1245 0101 b900 2f04 00b9
[error]     0x0000070: 0033 0300 3a09 1909 b600 399a 002f 1909
[error]     0x0000080: b600 3cc0 003e 3a0a 190a 3a0b 190b c600
[error]     0x0000090: 1c19 0bb6 0041 c000 433a 0c19 0cc1 0043
[error]     0x00000a0: 9900 0a19 0c3a 0da7 0006 a700 17b2 004a
[error]     0x00000b0: b200 4f19 0819 0db6 0053 b600 572b a700
[error]     0x00000c0: 0cbb 0059 592d b700 5bbf b0            
[error]   Stackmap Table:
[error]     append_frame(@88,Object[#67],Object[#53])
[error]     chop_frame(@170,1)
[error]     append_frame(@173,Object[#53])
[error]     chop_frame(@193,1)
[error]     full_frame(@202,{Object[#2],Object[#67],Object[#97],Object[#67],Object[#53]},{Object[#67]})
[error] 
[error] java.lang.Class.getDeclaredFields0(Native Method)
[error] java.lang.Class.privateGetDeclaredFields(Class.java:2583)
[error] java.lang.Class.getField0(Class.java:2975)
[error] java.lang.Class.getField(Class.java:1701)
[error] dotty.tools.dotc.transform.Splicer$Interpreter.loadModule(Splicer.scala:400)
[error] dotty.tools.dotc.transform.Splicer$Interpreter.liftedTree1$1(Splicer.scala:364)
[error] dotty.tools.dotc.transform.Splicer$Interpreter.interpretedStaticMethodCall(Splicer.scala:371)
[error] dotty.tools.dotc.transform.Splicer$Interpreter.interpretTree(Splicer.scala:267)
[error] dotty.tools.dotc.transform.Splicer$Interpreter.interpretTree$$anonfun$2(Splicer.scala:288)
[error] dotty.tools.dotc.transform.Splicer$.$anonfun$2(Splicer.scala:56)
[error] scala.Option.fold(Option.scala:263)
[error] dotty.tools.dotc.transform.Splicer$.splice(Splicer.scala:56)
[error] dotty.tools.dotc.typer.Inliner.dotty$tools$dotc$typer$Inliner$$expandMacro(Inliner.scala:1825)
[error] dotty.tools.dotc.typer.Inliner$InlineTyper.typedApply(Inliner.scala:1603)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2809)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:121)
[error] dotty.tools.dotc.typer.Inliner$InlineTyper.typedUnadapted(Inliner.scala:1686)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
[error] dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:62)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2814)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:121)
[error] dotty.tools.dotc.typer.Inliner$InlineTyper.typedUnadapted(Inliner.scala:1686)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2934)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
[error] dotty.tools.dotc.typer.Inliner.inlined(Inliner.scala:1054)
[error] dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:160)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:86)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:60)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1403)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:95)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:82)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:103)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:80)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:60)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:111)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:80)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1466)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:80)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:53)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:60)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1477)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:120)
[error] dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:94)
[error] dotty.tools.dotc.transform.Inlining$$anon$2.transform(Inlining.scala:72)
[error] dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:21)
[error] dotty.tools.dotc.transform.Inlining.run(Inlining.scala:44)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:308)
[error] scala.collection.immutable.List.map(List.scala:246)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:309)
[error] dotty.tools.dotc.transform.Inlining.runOn(Inlining.scala:48)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:259)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:270)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:278)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:287)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:220)
[error] dotty.tools.dotc.Run.compile(Run.scala:204)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:192)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:182)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:177)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:175)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:461)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:416)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:503)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:403)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:169)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2366)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2316)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30)
[error] sbt.internal.io.Retry$.apply(Retry.scala:46)
[error] sbt.internal.io.Retry$.apply(Retry.scala:28)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2314)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] java.lang.Thread.run(Thread.java:750)
[error]            
[error] stack trace is suppressed; run last Test / compileIncremental for the full output
[error] (Test / compileIncremental) java.lang.VerifyError: Bad local variable type
[error] Exception Details:
[error]   Location:
[error]     example/Macros$.fooImpl(Lscala/quoted/Expr;Lscala/quoted/Quotes;)Lscala/quoted/Expr; @179: aload
[error]   Reason:
[error]     Type top (current frame, locals[8]) is not assignable to reference type
[error]   Current Frame:
[error]     bci: @179
[error]     flags: { }
[error]     locals: { 'example/Macros$', 'scala/quoted/Expr', 'scala/quoted/Quotes', 'scala/quoted/Expr', 'scala/Option' }
[error]     stack: { 'scala/Predef$', 'scala/Tuple2$' }
[error]   Bytecode:
[error]     0x0000000: 2b4e 2dc6 00a7 2cc0 000b b900 2701 002d
[error]     0x0000010: 2cc0 0029 122b 0101 b900 2f04 00b9 0033
[error]     0x0000020: 0300 3a04 1904 b600 399a 002f 1904 b600
[error]     0x0000030: 3cc0 003e 3a05 1905 3a06 1906 c600 1c19
[error]     0x0000040: 06b6 0041 c000 433a 0719 07c1 0043 9900
[error]     0x0000050: 0a19 073a 08a7 0058 2cc0 000b b900 2701
[error]     0x0000060: 002d 2cc0 0029 1245 0101 b900 2f04 00b9
[error]     0x0000070: 0033 0300 3a09 1909 b600 399a 002f 1909
[error]     0x0000080: b600 3cc0 003e 3a0a 190a 3a0b 190b c600
[error]     0x0000090: 1c19 0bb6 0041 c000 433a 0c19 0cc1 0043
[error]     0x00000a0: 9900 0a19 0c3a 0da7 0006 a700 17b2 004a
[error]     0x00000b0: b200 4f19 0819 0db6 0053 b600 572b a700
[error]     0x00000c0: 0cbb 0059 592d b700 5bbf b0            
[error]   Stackmap Table:
[error]     append_frame(@88,Object[#67],Object[#53])
[error]     chop_frame(@170,1)
[error]     append_frame(@173,Object[#53])
[error]     chop_frame(@193,1)
[error]     full_frame(@202,{Object[#2],Object[#67],Object[#97],Object[#67],Object[#53]},{Object[#67]})
@xuwei-k xuwei-k added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 16, 2022
@nicolasstucki nicolasstucki added area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 16, 2022
@nicolasstucki
Copy link
Contributor

This code should emit the same error as

  def fooImpl(a: Any): Any = a match {
    case (x1: String) | (x2: Int) =>
      println((x1, x2))
      a
  }

@nicolasstucki
Copy link
Contributor

Either this check is not working properly or it should be repeated somewhere in QuotesAndSplices.scala.

@nicolasstucki nicolasstucki assigned aherlihy and unassigned aherlihy Mar 21, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 29, 2022
bishabosha pushed a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants