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 85c22c4ad..cfc92435c 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 @@ -3,6 +3,7 @@ import java.util.concurrent.atomic.AtomicInteger import scala.collection.immutable.ListMap import scala.quoted.* import scala.reflect.ClassTag +import scala.util.control.NonFatal private[surface] object CompileTimeSurfaceFactory: @@ -516,11 +517,15 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q): paramss.map { params => params.zipWithIndex .map((x, i) => (x, i + 1, x.tree)) - .collect { case (s: Symbol, i: Int, v: ValDef) => + .collect { case (s: Symbol, i: Int, d: Definition) => // E.g. case class Foo(a: String)(implicit b: Int) // println(s"=== ${v.show} ${s.flags.show} ${s.flags.is(Flags.Implicit)}") - // Substitue type param to actual types - val resolved: TypeRepr = v.tpt.tpe match + // Substitute type param to actual types + val (name: String, tpe: TypeRepr) = d match + case v: ValDef => (v.name, v.tpt.tpe) + case d: DefDef => (d.symbol.name, d.returnTpt.tpe) + + val resolved: TypeRepr = tpe match case a: AppliedType => val resolvedTypeArgs = a.args.map { case p if p.typeSymbol.isTypeParam && typeArgTable.contains(p.typeSymbol.name) => @@ -545,7 +550,8 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q): // println(s"=== target: ${m.name}, ${m.owner.name}") m.name == targetMethodName } - MethodArg(v.name, resolved, defaultValueGetter, defaultMethodArgGetter, isImplicit, isRequired, isSecret) + + MethodArg(name, resolved, defaultValueGetter, defaultMethodArgGetter, isImplicit, isRequired, isSecret) } } @@ -817,12 +823,12 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q): else // For generic functions, type params also need to be applied val dummyTypeParams = methodTypeParams.map(x => TypeRepr.of[Any]) - // println(s"---> ${m.name} type param count: ${methodTypeParams.size}, arg size: ${argList.size}") expr .appliedToTypes(dummyTypeParams) .appliedToArgss(argList) newExpr.changeOwner(sym) ) + if m.name == "aggregate" then println(s"--- ${lambda.show}") '{ Some(${ lambda.asExprOf[(Any, Seq[Any]) => Any] }) } private def localMethodsOf(t: TypeRepr): Seq[Symbol] = diff --git a/airframe-surface/src/test/scala/wvlet/airframe/surface/i3409.scala b/airframe-surface/src/test/scala/wvlet/airframe/surface/i3409.scala new file mode 100644 index 000000000..c04c0d6d0 --- /dev/null +++ b/airframe-surface/src/test/scala/wvlet/airframe/surface/i3409.scala @@ -0,0 +1,22 @@ +/* + * 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 i3409 extends AirSpec { + test("Seq[String]") { + Surface.methodsOf[Seq[String]] + } +}