Skip to content

Commit

Permalink
reproduce #3409
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Feb 26, 2024
1 parent ecc043b commit 8f88aba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
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 @@ -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] =
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]]
}
}

0 comments on commit 8f88aba

Please sign in to comment.