Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

surface (fix): Fix #3409 #3412

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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) =>
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -775,11 +781,12 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q):
methodArgss: List[List[MethodArg]]
): Expr[Option[(Any, Seq[Any]) => Any]] =
// Build { (x: Any, args: Seq[Any]) => x.asInstanceOf[t].<method>(.. args) }
val methodTypeParams: List[TypeParamClause] = m.tree match
val methodTypeParams: List[ParamClause] = m.tree match
case df: DefDef =>
df.paramss.collect { case t: TypeParamClause =>
t
df.paramss.foreach { p =>
if m.name == "collectFirst" then println(s"--- ${p}")
}
df.paramss.collect { case t: TypeParamClause => t }
case _ =>
List.empty

Expand Down Expand Up @@ -817,7 +824,7 @@ 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}")
// if m.name == "collectFirst" then println(s"${m.name}. ${m.declaredTypes}")
expr
.appliedToTypes(dummyTypeParams)
.appliedToArgss(argList)
Expand Down
22 changes: 22 additions & 0 deletions airframe-surface/src/test/scala/wvlet/airframe/surface/i3409.scala
Original file line number Diff line number Diff line change
@@ -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]]
}
}
Loading