Skip to content

Commit

Permalink
Implement workaround for Scala 2 enumerations (closes #3411)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSpanel committed Feb 29, 2024
1 parent ff20874 commit 744492b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -863,19 +863,24 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q):
name != "<init>"
}

allMethods.filter(m => isOwnedByTargetClass(m, t))
allMethods.filter(m => isOwnedByTargetClass(m, t) && !enumerationWorkaround(m, t))

private def nonObject(x: Symbol): Boolean =
!x.flags.is(Flags.Synthetic) &&
!x.flags.is(Flags.Artifact) &&
x.fullName != "scala.Any" &&
x.fullName != "java.lang.Object" &&
// Exclude caes class methods
// Exclude case class methods
x.fullName != "scala.Product"

private def isOwnedByTargetClass(m: Symbol, t: TypeRepr): Boolean =
m.owner == t.typeSymbol || t.baseClasses.filter(nonObject).exists(_ == m.owner)

// workaround https://github.com/lampepfl/dotty/issues/19825 - surface of enumeration value methods fails
private def enumerationWorkaround(m: Symbol, t: TypeRepr): Boolean =
t.baseClasses.exists(_.fullName.startsWith("scala.Enumeration.")) // this will match both Value and ValueSet
// note: it would be possible to let id, hashCode and equals pass through if desired

private def modifierBitMaskOf(m: Symbol): Int =
var mod = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object i3411 extends AirSpec {
val m = Surface.methodsOf[SomeEnum]
debug(s.params)
// enumeration type (value) usually contains at least the compare method
m.map(_.name) shouldContain "compare"
// note: we are unable to handle compare at the moment and some other methods inherited from Value, see https://github.com/lampepfl/dotty/issues/19825
// m.map(_.name) shouldContain "compare"
}
}

0 comments on commit 744492b

Please sign in to comment.