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): Fixes #3353 in building surfaces of classes with type params in Scala3 #3405

Merged
merged 2 commits into from
Feb 25, 2024
Merged
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 @@ -584,7 +584,10 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q):
// https://github.com/lampepfl/dotty-macro-examples/blob/aed51833db652f67741089721765ad5a349f7383/defaultParamsInference/src/macro.scala
val defaultValue: Expr[Option[Any]] = field.defaultValueGetter match
case Some(m) =>
val dv = Ref(m.owner.companionModule).select(m)
val companion = Ref(t.typeSymbol.companionModule)
// Populate method type parameters with Any type
val dummyTypeList: List[TypeRepr] = m.paramSymss.flatten.map { tp => TypeRepr.of[Any] }.toList
val dv: Term = companion.select(m).appliedToTypes(dummyTypeList)
'{ Some(${ dv.asExprOf[Any] }) }
case _ => '{ None }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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

/**
* Test generic types with default values
*/
object i3353 extends AirSpec:
case class FValue[V](value: Option[Int] = None)

test("With an optional value default argument") {
Surface.of[FValue[Int]]
}

case class MValue[T](value: Seq[T] = Seq.empty)

test("With a default value of a Seq type") {
Surface.of[MValue[Int]]
}

case class NValue[T >: Null](value: T = null)

test("With a default value of a generic type") {
Surface.of[NValue[String]]
}

case class BValue[T](value: T, boolean: Boolean = false)

test("With a default value of a generic type and regular arg") {
Surface.of[BValue[String]]
}

case class ZValue[T](boolean: Boolean = false)

test("With a default value of a boolean type") {
Surface.of[ZValue[String]]
}
Loading