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

Surface for Option with a default value crashing with Scala 3 #3353

Closed
OndrejSpanel opened this issue Jan 26, 2024 · 2 comments
Closed

Surface for Option with a default value crashing with Scala 3 #3353

OndrejSpanel opened this issue Jan 26, 2024 · 2 comments
Assignees
Labels

Comments

@OndrejSpanel
Copy link
Contributor

Following code compiles and runs fine with Scala 2.13.12, but causes compile-time exception with Scala 3.3.1 and 3.4.0-RC3:

import wvlet.airframe.surface.Surface

object Main {
  case class FValue[T](value: Option[Int] = None)

  def main(args: Array[String]): Unit = {
    Surface.of[FValue[Int]]
  }
}

Tested with

libraryDependencies += "org.wvlet.airframe" %% "airframe-surface" % "24.1.1"

The error is:

java.lang.Exception: Expected an expression. This is a partially applied Term. Try eta-expanding the term first.

Details

C:\Dev\surface-option-bug\src\main\scala\Main.scala:7:15 Exception occurred while executing macro expansion. java.lang.Exception: Expected an expression. This is a partially applied Term. Try eta-expanding the term first. at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExpr(QuotesImpl.scala:110) at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExprOf(QuotesImpl.scala:116) at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExprOf(QuotesImpl.scala:115) at wvlet.airframe.surface.CompileTimeSurfaceFactory.$anonfun$37(CompileTimeSurfaceFactory.scala:662) at wvlet.airframe.surface.CompileTimeSurfaceFactory.$anonfun$adapted$6(CompileTimeSurfaceFactory.scala:662) at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:110) at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1538) at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:135) at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1605) at scala.collection.immutable.List.mapConserve(List.scala:472) at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1605) at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1504) at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:135) at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:152) at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:88) at scala.quoted.runtime.impl.QuotesImpl.unpickleExprV2(QuotesImpl.scala:3143) at wvlet.airframe.surface.CompileTimeSurfaceFactory.$anonfun$36(CompileTimeSurfaceFactory.scala:662) at scala.collection.Iterator$$anon$9.next(Iterator.scala:584) at scala.collection.immutable.List.prependedAll(List.scala:153) at scala.collection.immutable.List$.from(List.scala:684) at scala.collection.immutable.List$.from(List.scala:681) at scala.collection.IterableOps$WithFilter.map(Iterable.scala:898) at wvlet.airframe.surface.CompileTimeSurfaceFactory.wvlet$airframe$surface$CompileTimeSurfaceFactory$$methodParametersOf(CompileTimeSurfaceFactory.scala:747) at wvlet.airframe.surface.CompileTimeSurfaceFactory.wvlet$airframe$surface$CompileTimeSurfaceFactory$$constructorParametersOf(CompileTimeSurfaceFactory.scala:632) at wvlet.airframe.surface.CompileTimeSurfaceFactory$$anon$12.applyOrElse(CompileTimeSurfaceFactory.scala:327) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:288) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at scala.PartialFunction$AndThen.applyOrElse(PartialFunction.scala:289) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:266) at wvlet.airframe.surface.CompileTimeSurfaceFactory.wvlet$airframe$surface$CompileTimeSurfaceFactory$$surfaceOf(CompileTimeSurfaceFactory.scala:138) at wvlet.airframe.surface.CompileTimeSurfaceFactory.surfaceOf(CompileTimeSurfaceFactory.scala:78) at wvlet.airframe.surface.CompileTimeSurfaceFactory$.surfaceOf(CompileTimeSurfaceFactory.scala:15)

Surface.of[FValue[Int]]

Scastie repro:

https://scastie.scala-lang.org/5ohvZnwMSX6k2hZvo8el7Q

@xerial xerial added the bug label Jan 26, 2024
@xerial xerial self-assigned this Jan 26, 2024
@xerial
Copy link
Member

xerial commented Jan 26, 2024

Thanks for the report and reproduction. I'll take a look

@OndrejSpanel
Copy link
Contributor Author

OndrejSpanel commented Jan 26, 2024

Other generic wrappers can cause the error too:

  case class MValue[T](value: Seq[T] = Seq.empty)
  Surface.of[MValue[Int]]
  case class NValue[T >: Null](value: T = null)
  Surface.of[NValue[String]]
  case class BValue[T](value: T, boolean: Boolean = false)
  Surface.of[BValue[String]]
  case class ZValue[T](boolean: Boolean = false)
  Surface.of[ZValue[String]]

xerial added a commit that referenced this issue Feb 25, 2024
@xerial xerial closed this as completed in a2c69a1 Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants