Skip to content

assertion failed: unresolved symbols: parameter v when pickling #16355

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
kubukoz opened this issue Nov 16, 2022 · 4 comments · Fixed by #16362
Closed

assertion failed: unresolved symbols: parameter v when pickling #16355

kubukoz opened this issue Nov 16, 2022 · 4 comments · Fixed by #16362
Assignees
Labels
Milestone

Comments

@kubukoz
Copy link
Contributor

kubukoz commented Nov 16, 2022

Compiler version

3.2.1

Minimized code

//> using scala "3.2.1"
import scala.quoted.Expr
import scala.quoted.Type
import scala.quoted.quotes
import scala.quoted.Quotes

object macros {

  inline transparent def mkNames[A]: List[Any] = ${ mkNamesImpl[A] }

  def mkNamesImpl[A: Type](using Quotes): Expr[List[Any]] = {
    import quotes.reflect._

    val fieldNames = TypeRepr.of[A].typeSymbol.declaredFields.map(_.name)

    val types = fieldNames
      .map { f =>
        val t1 = ConstantType(StringConstant(f))
        t1.asType match {
          case '[t1Type] => TypeRepr.of[(t1Type, "aa")]
        }
      }
      .reduceLeft[TypeRepr](OrType(_, _))

    types.asType match {
      case '[ttt] =>
        Expr.ofList[ttt](
          fieldNames.map { v =>
            Expr[(v.type, "aa")](v -> "aa").asExprOf[ttt]
          }
        )
    }
  }

}

Output (click arrow to expand)

Error compiling project (Scala 3.2.1, JVM)
Error: Unexpected error when compiling project_f0e8bc45bf: 'assertion failed: unresolved symbols: parameter v (line 27) #18316 when pickling /Users/kubukoz/projects/demos/macros.scala'
Compilation failed
@kubukoz kubukoz added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 16, 2022
@kubukoz kubukoz changed the title assertion failed: unresolved symbols: parameter v (line 27) #18316 when pickling assertion failed: unresolved symbols: parameter v when pickling Nov 16, 2022
@jchyb jchyb added area:metaprogramming:reflection Issues related to the quotes reflection API 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 Nov 17, 2022
@jchyb
Copy link
Contributor

jchyb commented Nov 17, 2022

Minimized:

import scala.quoted._

object macros {

  inline transparent def mkNames: Unit = ${ mkNamesImpl }

  def mkNamesImpl(using Quotes): Expr[Unit] = {
    val v = "name"
    Expr[(v.type, "aa")](v -> "aa")
    '{()}
  }

}

@jchyb jchyb removed the area:metaprogramming:reflection Issues related to the quotes reflection API label Nov 17, 2022
@kubukoz
Copy link
Contributor Author

kubukoz commented Nov 17, 2022

thank you :)

@nicolasstucki
Copy link
Contributor

Minimized further

import scala.quoted._
def mkNamesImpl(v: String)(using Quotes): Expr[Any] =
  // Type.of[Option[v.type]] // error: access to parameter v from wrong staging level // this is OK
  val _: Type[Option[v.type]] = Type.of // issue: access to parameter v from wrong staging level not found in inferred type
  ???

@nicolasstucki
Copy link
Contributor

Minimal

import scala.quoted._
def test(v: String)(using Quotes): Type[v.type] = Type.of

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 17, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 18, 2022
@Kordyjan Kordyjan added this to the Future versions milestone Dec 12, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 9, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 20, 2023
@nicolasstucki nicolasstucki self-assigned this Jan 20, 2023
@Kordyjan Kordyjan modified the milestones: Future versions, 3.3.1 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants