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..4475a181d 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 @@ -574,6 +574,7 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q): val methodName = method.name val methodArgs = methodArgsOf(t, method).flatten val argClasses = methodArgs.map { arg => + // check if type is referencing t, which is something.InnerType, but via a base class, like Base.this.InnerType clsOf(arg.tpe.dealias) } val isConstructor = t.typeSymbol.primaryConstructor == method @@ -678,6 +679,7 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q): methodArgAccessor = ${ methodArgAccessor } ) } + println(paramExprs.map(_.show).mkString("\n")) Expr.ofSeq(paramExprs) private def getTree(e: Expr[?]): Tree = @@ -745,7 +747,7 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q): methodsOfInternal(t).asTerm ).asExprOf[Seq[MethodSurface]] - // println(s"=== methodOf: ${t.typeSymbol.fullName} => \n${expr.show}") + println(s"=== methodOf: ${t.typeSymbol.fullName} => \n${expr.show}") expr private val seenMethodParent = scala.collection.mutable.Set[TypeRepr]() @@ -863,19 +865,28 @@ 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 = { + val params = methodParametersOf(t, m) + val args = methodArgsOf(t, m).flatten + println(s"m $m ${args.map(_.tpe.show).mkString(",")} ${params.show}") + 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/i3439.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/i3439.scala new file mode 100644 index 000000000..254cfe4ad --- /dev/null +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/i3439.scala @@ -0,0 +1,35 @@ +/* + * 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 i3439 extends AirSpec { + + trait Base { + class InnerType { + def compare(that: InnerType): Int = 0 + } + } + + object OuterType extends Base { + def create: InnerType = new InnerType + } + + test("Handle inherited inner class") { + //val mm = Surface.methodsOf[OuterType.type] + val m = Surface.methodsOf[OuterType.InnerType] + //m.map(_.name) shouldContain "compare" + } +}