Open
Description
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:
Test.scala
which summons an instance ofcats.Show[String]
using fourinline
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 }
TastyQueryTest.scala
which logs the AST of each method call usingtasty-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
.