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

Stripping generic type with asExprOf does not recover it in transparent inline when passing it to another function #22886

Open
andrzejressel opened this issue Mar 28, 2025 · 0 comments
Labels

Comments

@andrzejressel
Copy link
Contributor

andrzejressel commented Mar 28, 2025

Compiler version

3.3.5
3.6.4
3.7.0-RC1

Minimized code

Macros.scala

import scala.quoted._

inline transparent def generateListPure(): List[?] = {
  ${ generateListPureImpl }
}

inline transparent def generateList(): List[?] = {
  ${ generateListImpl }
}

inline transparent def generateListWithMatch(): List[?] = {
  ${ generateListWithMatchImpl }
}

private def generateListPureImpl(using Quotes): Expr[List[?]] = {
  val myExpr = '{ List(1) }.asExprOf[List[?]]

  '{ $myExpr }
}

private def generateListImpl(using Quotes): Expr[List[?]] = {
  val myExpr = '{ List(1) }.asExprOf[List[?]]

  '{ doSomethingWithList($myExpr) }
}

private def generateListWithMatchImpl(using Quotes): Expr[List[?]] = {
  val myExpr = '{ List(1) }.asExprOf[List[?]]

  myExpr match {
    case '{ $typedList: List[in] } =>
      '{ doSomethingWithList($typedList) }
  }
}

private def doSomethingWithList[T](l: List[T]): List[T] = l

inline transparent def getInnerType[E](l: List[E]) = {
  ${ getInnerTypeImpl('l) }
}

private def getInnerTypeImpl[E: Type](l: Expr[List[E]])(using Quotes): Expr[String] = {
  val s = Type.show[E]
  Expr.apply(s)
}

Test.scala

@main
def main(): Unit = {
  val innerTypePure = getInnerType(generateListPure())
  val innerType = getInnerType(generateList())
  val innerTypeWithMatch = getInnerType(generateListWithMatch())

  println(s"Pure: $innerTypePure")
  println(s"Normal: $innerType")
  println(s"With match: $innerTypeWithMatch")
}

Output

Pure: scala.Int
Normal: scala.Any
With match: scala.Int

Expectation

Pure: scala.Int
Normal: scala.Int
With match: scala.Int
@andrzejressel andrzejressel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 28, 2025
@andrzejressel andrzejressel changed the title Stripping type with asExprOf does not recover it in transparent inline Stripping generic type with asExprOf does not recover it in transparent inline Mar 28, 2025
@andrzejressel andrzejressel changed the title Stripping generic type with asExprOf does not recover it in transparent inline Stripping generic type with asExprOf does not recover it in transparent inline when passing it to another function Mar 28, 2025
@Gedochao Gedochao added area:inline 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 Apr 1, 2025
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