Skip to content

Compiler hang forever when arbitrary type in arrow closure #8746

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
deusaquilus opened this issue Apr 19, 2020 · 4 comments
Closed

Compiler hang forever when arbitrary type in arrow closure #8746

deusaquilus opened this issue Apr 19, 2020 · 4 comments

Comments

@deusaquilus
Copy link
Contributor

Minimized code

When attempting a quoted match an arrow closure with arbitrary types in a macro:

tree.unseal.underlyingArgument.seal match {
    case '{ ($in: $tpe1) => ($out: $tpe2) } => Expr(out.toString)
}

E.g. when matching the following expression:

mac((x: String) => "anything")

The compiler hangs forever. It does not seem to be doing anything.

Expectation

The expression should match and compile property.

Code Sample

Code sample is available here:
https://github.com/deusaquilus/arrow_forever_bug

@nicolasstucki
Copy link
Contributor

You should be using inline parameters rather than underlyingArgument.

@nicolasstucki
Copy link
Contributor

Minimized to

import scala.quoted._

object Macro {
  inline def mac(): String = ${ macImpl() }
  def macImpl()(using qctx: QuoteContext): Expr[String] =
    '{(x: String) => "anything"} match
      case '{ (in: String) => ($out: $tpe2) } => Expr(out.toString)
      case _ => ???

}
import scala.quoted._

object Macro {
  inline def mac(): String = ${ macImpl() }
  def macImpl()(using qctx: QuoteContext): Expr[String] =
    '{(x: String) => "anything"} match
      case '{ (in: String) => ($out: $tpe2) } => Expr(out.toString)
      case _ => ???

}
import Macro._

@main def testOtherstuff() = { // hello
  mac()
}

@nicolasstucki
Copy link
Contributor

Some side notes to improve the code

  • import qctx.tasty.{given _, _} now can be import qctx.tasty._
  • Use inline parameters instead of underlyingArgument

liufengyun added a commit that referenced this issue Apr 22, 2020
Fix #8746: Fix quote matcher block normalization
@deusaquilus
Copy link
Contributor Author

You should be using inline parameters rather than underlyingArgument.

@nicolasstucki Like I mentioned before, we really, really, need to use underlyingArgument to get rid of the Inline nodes for the sake of our parser. I think many other macro framework authors will come to the same conclusion when they start writing complex pattern-matching code on tasty-reflect trees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants