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

ExprMap cannot map over call sites taking by name parameters #15228

Closed
rmgk opened this issue May 18, 2022 · 1 comment · Fixed by #15269
Closed

ExprMap cannot map over call sites taking by name parameters #15228

rmgk opened this issue May 18, 2022 · 1 comment · Fixed by #15269
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Milestone

Comments

@rmgk
Copy link

rmgk commented May 18, 2022

Compiler version

3.1.2, Scala 3.2.0-RC1-bin-20220517-e5abec0-NIGHTLY

Minimized code

Boilerplate to just do an empty transform using ExpMap

import scala.quoted.*

inline def mac[T](inline expr: T): T =
  ${ impl('expr) }

class MyMap() extends ExprMap {
  override def transform[T](e: Expr[T])(using Type[T])(using q: Quotes): Expr[T] =
    transformChildren(e)
}

def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = {
  MyMap().transform(expr)
}

Then call with something that takes a by name parameter, for example mac(None.getOrElse(3))

Output

java.lang.Exception: Expr cast exception: 3
of type: 3
did not conform to type:  => scala.Int
	at scala.quoted.runtime.impl.QuotesImpl.asExprOf(QuotesImpl.scala:71)
	at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExprOf(QuotesImpl.scala:114)
	at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExprOf(QuotesImpl.scala:113)
	at scala.quoted.ExprMap.transformChildren(ExprMap.scala:150)
	at scala.quoted.ExprMap.transformChildren$(ExprMap.scala:3)

Expectation

Should return the unmodified expression

@rmgk rmgk added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 18, 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 May 19, 2022
@nicolasstucki nicolasstucki self-assigned this May 19, 2022
@nicolasstucki
Copy link
Contributor

We probably need to strip the ByNameType types here https://github.com/lampepfl/dotty/blob/main/library/src/scala/quoted/ExprMap.scala#L51.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 23, 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 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants