Skip to content

Problem with interpreting value class selections #3916

Closed
@liufengyun

Description

@liufengyun

This issue tracks a known problem with the PR #3913. The problem can be demonstrated with the following code.

  1. File macro.scala
import scala.quoted._

class FInterpolatorHelper(val sc: StringContext) extends AnyVal {
  inline def ff(arg1: Any): String = ~FInterpolation.fInterpolation(sc, Seq('(arg1)))
  inline def ff(arg1: Any, arg2: Any): String = ~FInterpolation.fInterpolation(sc, Seq('(arg1), '(arg2)))
  inline def ff(arg1: Any, arg2: Any, arg3: Any): String = ~FInterpolation.fInterpolation(sc, Seq('(arg1), '(arg2), '(arg3)))
  // ...
}

object FInterpolation {
  private def liftSeq(args: Seq[Expr[Any]]): Expr[Seq[Any]] = args match {
    case x :: xs  => '{ (~x) +: ~(liftSeq(xs))  }
    case Nil => '(Seq(): Seq[Any])
  }

  def fInterpolation(sc: StringContext, args: Seq[Expr[Any]]): Expr[String] = {
    val str: Expr[String] = sc.parts.mkString("")
    val args1: Expr[Seq[Any]] = liftSeq(args)
    '{  (~str).format(~args1: _*) }
  }
}
  1. File Test.scala
 object Test {
  def main(args: Array[String]): Unit = {
    println(new FInterpolatorHelper(StringContext("hello%s")).ff(5))
  }
}

The compiler crashes while compiling Test.scala, with the following log:

Full log -- Error: /Users/fliu/Documents/dotty/tests/run/f-interpolator/Test_2.scala:7:9 3 | // println(ff"string: ${"l"}%s") | ^ |A runtime exception occurred while interpreting |argument type mismatch |java.lang.IllegalArgumentException: argument type mismatch | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | at java.lang.reflect.Method.invoke(Method.java:498) | at dotty.tools.dotc.interpreter.Interpreter.$anonfun$interpretTreeImpl$5(Interpreter.scala:100) | at dotty.tools.dotc.interpreter.Interpreter.interpreted(Interpreter.scala:188) | at dotty.tools.dotc.interpreter.Interpreter.interpretTreeImpl(Interpreter.scala:100) | at dotty.tools.dotc.interpreter.Interpreter.interpretTree(Interpreter.scala:47) | at dotty.tools.dotc.transform.Splicer$.reflectiveSplice(Splicer.scala:27) | at dotty.tools.dotc.transform.Splicer$.splice(Splicer.scala:21) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.$anonfun$transform$3(ReifyQuotes.scala:330) | at dotty.tools.dotc.reporting.trace$.op1$2(trace.scala:25) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:26) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:36) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.transform(ReifyQuotes.scala:310) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.$anonfun$transform$6(Trees.scala:1221) | at scala.collection.immutable.List.mapConserve(List.scala:176) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1221) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1134) | at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:62) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.super$transform(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.mapOverTree$1(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.$anonfun$transform$3(ReifyQuotes.scala:341) | at dotty.tools.dotc.reporting.trace$.op1$2(trace.scala:25) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:26) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:36) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.transform(ReifyQuotes.scala:310) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1148) | at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:62) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.super$transform(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.mapOverTree$1(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.$anonfun$transform$3(ReifyQuotes.scala:326) | at dotty.tools.dotc.reporting.trace$.op1$2(trace.scala:25) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:26) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:36) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.transform(ReifyQuotes.scala:310) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1198) | at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:54) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.super$transform(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.mapOverTree$1(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.$anonfun$transform$3(ReifyQuotes.scala:341) | at dotty.tools.dotc.reporting.trace$.op1$2(trace.scala:25) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:26) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:36) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.transform(ReifyQuotes.scala:310) | at dotty.tools.dotc.transform.MacroTransform$Transformer.transformStat$1(MacroTransform.scala:43) | at dotty.tools.dotc.transform.MacroTransform$Transformer.$anonfun$transformStats$1(MacroTransform.scala:46) | 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.transform.MacroTransform$Transformer.transformStats(MacroTransform.scala:46) | at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:60) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.super$transform(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.mapOverTree$1(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.$anonfun$transform$3(ReifyQuotes.scala:341) | at dotty.tools.dotc.reporting.trace$.op1$2(trace.scala:25) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:26) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:36) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.transform(ReifyQuotes.scala:310) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1201) | at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:54) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.super$transform(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.mapOverTree$1(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.$anonfun$transform$3(ReifyQuotes.scala:341) | at dotty.tools.dotc.reporting.trace$.op1$2(trace.scala:25) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:26) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:36) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.transform(ReifyQuotes.scala:310) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.$anonfun$transform$6(Trees.scala:1221) | at scala.collection.immutable.List.mapConserve(List.scala:176) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1221) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1219) | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1207) | at dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:54) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.super$transform(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.mapOverTree$1(ReifyQuotes.scala:312) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.$anonfun$transform$3(ReifyQuotes.scala:341) | at dotty.tools.dotc.reporting.trace$.op1$2(trace.scala:25) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:26) | at dotty.tools.dotc.reporting.trace$.apply(trace.scala:36) | at dotty.tools.dotc.transform.ReifyQuotes$Reifier.transform(ReifyQuotes.scala:310) | at dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:22) | at dotty.tools.dotc.transform.ReifyQuotes.run(ReifyQuotes.scala:31) | at dotty.tools.dotc.core.Phases$Phase.$anonfun$runOn$1(Phases.scala:293) | at scala.collection.immutable.List.map(List.scala:283) | at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:291) | at dotty.tools.dotc.core.Phases$Phase.runOn$(Phases.scala:290) | at dotty.tools.dotc.transform.MacroTransform.runOn(MacroTransform.scala:16) | at dotty.tools.dotc.Run.$anonfun$compileUnits$3(Run.scala:163) | at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) | at dotty.tools.dotc.util.Stats$.trackTime(Stats.scala:47) | at dotty.tools.dotc.Run.$anonfun$compileUnits$2(Run.scala:161) | at dotty.tools.dotc.Run.$anonfun$compileUnits$2$adapted(Run.scala:159) | 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:191) | at dotty.tools.dotc.Run.runPhases$1(Run.scala:159) | at dotty.tools.dotc.Run.$anonfun$compileUnits$1(Run.scala:179) | at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) | at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:88) | at dotty.tools.dotc.Run.compileUnits(Run.scala:145) | at dotty.tools.dotc.Run.compileSources(Run.scala:132) | at dotty.tools.dotc.Run.compile(Run.scala:116) | at dotty.tools.dotc.Driver.doCompile(Driver.scala:29) | at dotty.tools.dotc.Driver.process(Driver.scala:127) | at dotty.tools.dotc.Driver.process(Driver.scala:96) | at dotty.tools.dotc.Driver.process(Driver.scala:108) | at dotty.tools.dotc.Driver.main(Driver.scala:135) | at dotty.tools.dotc.Main.main(Main.scala) | one error found java.lang.RuntimeException: Nonzero exit code returned from runner: 1 at scala.sys.package$.error(package.scala:27)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions