Skip to content

TASTy does not include reference to resolved term when using summonAll and summonFrom #22701

Open
@mrdziuban

Description

@mrdziuban

Compiler version

3.3.5, 3.4.3, 3.5.2, and 3.6.3

Minimized code

https://github.com/mrdziuban/scala3-compiletime-tasty

That repo contains two files:

  1. Test.scala which summons an instance of cats.Show[String] using four inline methods:
    val instWithSummon = summon[cats.Show[String]]
    val instWithSummonAll = compiletime.summonAll[cats.Show[String] *: EmptyTuple]
    val instWithSummonInline = compiletime.summonInline[cats.Show[String]]
    inline def instWithSummonFrom = compiletime.summonFrom { case s: cats.Show[String] => s }
  2. TastyQueryTest.scala which logs the AST of each method call using tasty-query

Output

The output of TastyQueryTest.scala shows that the calls to instWithSummon and instWithSummonInline contain a reference to catsShowForString, which is the instance that satisfies the implicit search, but neither instWithSummonAll nor instWithSummonFrom have a reference to it

expand output
********************************************************************************
instWithSummon:
  Inlined(
    expr = Inlined(
      expr = Ident(
        name = UniqueName(underlying = SimpleName(name = "x"), separator = "$proxy", num = 1)
      ),
      caller = None,
      bindings = List()
    ),
    caller = Some(
      value = TypeIdent(name = ObjectClassTypeName(underlying = SimpleTypeName(name = "Predef")))
    ),
    bindings = List(
      ValDef(
        name = UniqueName(underlying = SimpleName(name = "x"), separator = "$proxy", num = 1),
        tpt = TypeWrapper(
          tp = AppliedType(TypeRef(PackageRef(cats), Show), List(TypeRef(TermRef(PackageRef(scala), Predef), String)))
        ),
        rhs = Some(value = Ident(name = SimpleName(name = "catsShowForString"))),
        symbol = symbol[instWithSummon>x$proxy1]
      )
    )
  )
********************************************************************************

********************************************************************************
instWithSummonAll:
  TypeApply(
    fun = Select(
      qualifier = Select(
        qualifier = Ident(name = SimpleName(name = "compiletime")),
        name = SimpleName(name = "package$package")
      ),
      name = SignedName(
        underlying = SimpleName(name = "summonAll"),
        sig = Signature(
          paramsSig = List(TypeLen(len = 1)),
          resSig = SignatureName(
            items = List(SimpleName(name = "scala"), SimpleName(name = "Product"))
          )
        ),
        target = SimpleName(name = "summonAll")
      )
    ),
    args = List(
      AppliedTypeTree(
        tycon = TypeIdent(name = SimpleTypeName(name = "*:")),
        args = List(
          AppliedTypeTree(
            tycon = SelectTypeTree(
              qualifier = TypeWrapper(tp = PackageRef(cats)),
              name = SimpleTypeName(name = "Show")
            ),
            args = List(TypeIdent(name = SimpleTypeName(name = "String")))
          ),
          TypeIdent(name = SimpleTypeName(name = "EmptyTuple"))
        )
      )
    )
  )
********************************************************************************

********************************************************************************
instWithSummonInline:
  Ident(name = SimpleName(name = "catsShowForString"))
********************************************************************************

********************************************************************************
instWithSummonFrom:
  Typed(
    expr = InlineMatch(
      selector = None,
      cases = List(
        CaseDef(
          pattern = Bind(
            name = SimpleName(name = "s"),
            body = TypeTest(
              body = WildcardPattern(
                tpe = AppliedType(TypeRef(PackageRef(cats), Show), List(TypeRef(TermRef(PackageRef(scala), Predef), String)))
              ),
              tpt = AppliedTypeTree(
                tycon = SelectTypeTree(
                  qualifier = TypeWrapper(tp = PackageRef(cats)),
                  name = SimpleTypeName(name = "Show")
                ),
                args = List(TypeIdent(name = SimpleTypeName(name = "String")))
              )
            ),
            symbol = symbol[instWithSummonFrom>s]
          ),
          guard = None,
          body = Block(
            stats = List(),
            expr = Typed(
              expr = Ident(name = SimpleName(name = "s")),
              tpt = TypeWrapper(
                tp = AppliedType(TypeRef(PackageRef(cats), Show), List(TypeRef(TermRef(PackageRef(scala), Predef), String)))
              )
            )
          )
        )
      )
    ),
    tpt = TypeWrapper(
      tp = AppliedType(TypeRef(PackageRef(cats), Show), List(TypeRef(TermRef(PackageRef(scala), Predef), String)))
    )
  )
********************************************************************************

Expectation

I would expect the TASTy for all four of these calls to have a reference to catsShowForString.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions