Skip to content

Commit

Permalink
fix nested intersection aliases (dotty) (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitlangton authored Nov 24, 2021
1 parent 0951ffb commit 50def11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,39 +159,27 @@ abstract class Inspector(protected val shift: Int) extends InspectorBase {
}
}

private def flattenInspectAnd(and: AndType): Set[AppliedReference] = {
val (andTypes, otherTypes) =
and match {
case AndType(l @ AndType(_, _), r @ AndType(_, _)) =>
(Set(l, r), Set.empty[TypeRepr])
case AndType(l @ AndType(_, _), r) =>
(Set(l), Set(r))
case AndType(l, r @ AndType(_, _)) =>
(Set(r), Set(l))
case AndType(l, r) =>
(Set.empty[AndType], Set(l, r))
}
val andTypeTags = andTypes.flatMap(flattenInspectAnd)
val otherTypeTags = otherTypes.map(inspectTypeRepr(_).asInstanceOf[AppliedReference])
andTypeTags ++ otherTypeTags
}
private def flattenAnd(typeRepr: TypeRepr): Set[TypeRepr] =
typeRepr.dealias match {
case AndType(l, r) =>
flattenAnd(l) ++ flattenAnd(r)
case other =>
Set(other)
}

private def flattenInspectOr(or: OrType): Set[AppliedReference] = {
val (orTypes, otherTypes) =
or match {
case OrType(l @ OrType(_, _), r @ OrType(_, _)) =>
(Set(l, r), Set.empty[TypeRepr])
case OrType(l @ OrType(_, _), r) =>
(Set(l), Set(r))
case OrType(l, r @ OrType(_, _)) =>
(Set(r), Set(l))
case OrType(l, r) =>
(Set.empty[OrType], Set(l, r))
}
val orTypeTags = orTypes flatMap flattenInspectOr
val otherTypeTags = otherTypes.map(inspectTypeRepr(_).asInstanceOf[AppliedReference])
orTypeTags ++ otherTypeTags
}
private def flattenOr(typeRepr: TypeRepr): Set[TypeRepr] =
typeRepr.dealias match {
case OrType(l, r) =>
flattenAnd(l) ++ flattenAnd(r)
case other =>
Set(other)
}

private def flattenInspectAnd(and: AndType): Set[AppliedReference] =
flattenAnd(and).map(inspectTypeRepr(_).asInstanceOf[AppliedReference])

private def flattenInspectOr(or: OrType): Set[AppliedReference] =
flattenOr(or).map(inspectTypeRepr(_).asInstanceOf[AppliedReference])

private[dottyreflection] def makeNameReferenceFromType(t: TypeRepr): NameReference = {
t match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ abstract class SharedTagTest extends AnyWordSpec with XY[String] with TagAsserti
"handle singleton types" in {
assertChild(Tag[ClockLive.type].tag, Tag[Clock].tag)
}

"handle nested intersection aliases" in {
type Inner = Int with String
type Outer = Boolean with Inner
assertChild(Tag[Outer].tag, Tag[Boolean with Int with String].tag)
assertChild(Tag[Boolean with Int with String].tag, Tag[Outer].tag)
}
}

}

0 comments on commit 50def11

Please sign in to comment.