Skip to content

Commit c9dbecc

Browse files
committed
Make dependently-typed members of u.tasty stable
Without this change, `showExtractors` is unstable and so is `showExtractors.tasty`, so `showExtractors.showTypeOrBounds`'s type gets approximated from `showExtractors.tasty.TypeOrBounds` to its bounds (`Any` or `Nothing` depending on variance), so the additions to the testcase fail. The same applies to other members. I also tried replacing `tasty.Tree` with `T#Tree` (and so on), but apparently those two types aren't considered equal, at least by Scalac (which is arguably a bug). Relates to code added in #4577.
1 parent 2a6bfeb commit c9dbecc

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

compiler/src/dotty/tools/dotc/tasty/TastyImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ object TastyImpl extends scala.tasty.Tasty {
2929

3030
// ===== Show =====================================================
3131

32-
def defaultShow: Show[this.type] = showExtractors
32+
val showExtractors: Show[this.type] = new ShowExtractors(this)
3333

34-
def showExtractors: Show[this.type] = new ShowExtractors(this)
34+
val defaultShow: Show[this.type] = showExtractors
3535

3636
// TODO
3737
// def showSourceCode: Show[this.type] = ???

library/src/scala/tasty/Tasty.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ abstract class Tasty { tasty =>
1919

2020
// ===== Show =====================================================
2121

22-
implicit def defaultShow: Show[tasty.type]
22+
implicit val defaultShow: Show[tasty.type]
2323

24-
def showExtractors: Show[tasty.type]
24+
val showExtractors: Show[tasty.type]
2525

2626
// TODO
2727
// def showSourceCode: Show[tasty.type]

tests/run/tasty-macro-assert/quoted_1.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ object Asserts {
2222

2323
def isOps(tpe: TypeOrBounds): Boolean = tpe match {
2424
case Type.SymRef(DefDef("Ops", _, _, _, _),
25-
Type.SymRef(ValDef("Asserts", _, _),
25+
pre @ Type.SymRef(ValDef("Asserts", _, _),
2626
Type.ThisType(Type.SymRef(PackageDef("<empty>", _), NoPrefix())))) =>
27+
val tpeShow = tpe.show
28+
val tpeShow1 = showExtractors.showTypeOrBounds(tpe)(u.context)
29+
val preShow = pre.show
30+
val preShow1 = showExtractors.showTypeOrBounds(pre)(u.context)
31+
assert(tpeShow == tpeShow1)
32+
assert(preShow == preShow1)
33+
println(tpeShow)
34+
println(preShow)
2735
true
2836
case _ => false
2937
}

0 commit comments

Comments
 (0)