diff --git a/airframe-surface/src/main/scala-3/wvlet/airframe/surface/CompileTimeSurfaceFactory.scala b/airframe-surface/src/main/scala-3/wvlet/airframe/surface/CompileTimeSurfaceFactory.scala index 58831ffe9..adbfb12bb 100644 --- a/airframe-surface/src/main/scala-3/wvlet/airframe/surface/CompileTimeSurfaceFactory.scala +++ b/airframe-surface/src/main/scala-3/wvlet/airframe/surface/CompileTimeSurfaceFactory.scala @@ -863,19 +863,24 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q): name != "" } - 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 diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/i3411.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/i3411.scala new file mode 100644 index 000000000..041679100 --- /dev/null +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/i3411.scala @@ -0,0 +1,36 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wvlet.airframe.surface + +import wvlet.airspec.AirSpec + +object i3411 extends AirSpec { + + object SomeEnum extends Enumeration { + type SomeEnum = Value + + val A, B, C = Value + } + + import SomeEnum.SomeEnum + + test("Handle a Scala 2 enumeration") { + val s = Surface.of[SomeEnum] // just check there is no error - no expected properties + val m = Surface.methodsOf[SomeEnum] + debug(s.params) + // enumeration type (value) usually contains at least the compare method + // 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" + } +}