Skip to content

Commit 9b1c0f5

Browse files
committed
test GenIso with inner classes
1 parent 3b08265 commit 9b1c0f5

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with
383383
}
384384

385385
object Ident extends IdentModule {
386-
def apply(tmref: TermRef)(implicit ctx: Context): Ident =
387-
withDefaultPos(implicit ctx => tpd.Ident(tmref))
386+
def apply(tmref: TermRef)(implicit ctx: Context): Term =
387+
withDefaultPos(implicit ctx => tpd.ref(tmref).asInstanceOf[Term])
388388

389389
def copy(original: Tree)(name: String)(implicit ctx: Context): Ident =
390390
tpd.cpy.Ident(original)(name.toTermName)

library/src/scala/tasty/reflect/TreeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ trait TreeOps extends Core {
248248
/** Scala term identifier */
249249
val Ident: IdentModule
250250
abstract class IdentModule {
251-
def apply(tmref: TermRef)(implicit ctx: Context): Ident
251+
def apply(tmref: TermRef)(implicit ctx: Context): Term
252252

253253
def copy(original: Tree)(name: String)(implicit ctx: Context): Ident
254254

tests/run-with-compiler/i5941/usage_2.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,19 @@ object Test {
4040
assert(jNum(3.5) == JNum(3.5))
4141
assert(jNum.getOption(JNum(3.5)) == Some(3.5))
4242
assert(jNum.getOption(JNull) == None)
43+
44+
// inner classes
45+
val inner = new Inner
46+
assert(GenIso[inner.JStr, String].to(inner.JStr("Hello")) == "Hello")
47+
assert(GenIso.unit[inner.JNull.type].to(inner.JNull) == 1)
48+
assert(GenIso.unit[inner.JNull.type].from(1) == inner.JNull)
4349
}
50+
}
51+
52+
class Inner {
53+
sealed trait Json
54+
case object JNull extends Json
55+
case class JStr(v: String) extends Json
56+
case class JNum(v: Double) extends Json
57+
case class JObj(v: Map[String, Json]) extends Json
4458
}

0 commit comments

Comments
 (0)