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

Generate in Scala 3 macro typeId without type parameters (#694) #702

Merged
merged 1 commit into from
Jul 14, 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 @@ -121,7 +121,7 @@ private case class DeriveSchema()(using val ctx: Quotes) {
val selfRefSymbol = Symbol.newVal(Symbol.spliceOwner, s"derivedSchema${stack.size}", TypeRepr.of[Schema[T]], Flags.Lazy, Symbol.noSymbol)
val selfRef = Ref(selfRefSymbol)

val typeInfo = '{TypeId.parse(${Expr(TypeRepr.of[T].show)})}
val typeInfo = '{TypeId.parse(${Expr(TypeRepr.of[T].classSymbol.get.fullName.replaceAll("\\$", ""))})}
val isEnumCase = Type.of[T] match {
case '[reflect.Enum] => true
case _ => false
Expand Down Expand Up @@ -201,7 +201,7 @@ private case class DeriveSchema()(using val ctx: Quotes) {
List('{zio.schema.annotation.genericTypeInfo(ListMap.from(${typeMembersExpr}.zip(${typeArgsExpr}.map(name => TypeId.parse(name).asInstanceOf[TypeId.Nominal]))))})
} else List.empty
val annotations = '{ zio.Chunk.fromIterable(${Expr.ofSeq(annotationExprs)}) ++ zio.Chunk.fromIterable(${Expr.ofSeq(docAnnotationExpr)}) ++ zio.Chunk.fromIterable(${Expr.ofSeq(genericAnnotations)}) }
val typeInfo = '{TypeId.parse(${Expr(TypeRepr.of[T].show)})}
val typeInfo = '{TypeId.parse(${Expr(TypeRepr.of[T].classSymbol.get.fullName.replaceAll("\\$", ""))})}

val applied = if (labels.length <= 22) {

Expand Down Expand Up @@ -390,7 +390,7 @@ private case class DeriveSchema()(using val ctx: Quotes) {
} else List.empty
val annotations = '{ zio.Chunk.fromIterable(${Expr.ofSeq(annotationExprs)}) ++ zio.Chunk.fromIterable(${Expr.ofSeq(docAnnotationExpr.toList)}) ++ zio.Chunk.fromIterable(${Expr.ofSeq(genericAnnotations)}) }

val typeInfo = '{TypeId.parse(${Expr(TypeRepr.of[T].show)})}
val typeInfo = '{TypeId.parse(${Expr(TypeRepr.of[T].classSymbol.get.fullName.replaceAll("\\$", ""))})}

val applied = if (cases.length <= 22) {
val args = List(typeInfo) ++ cases :+ annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ import zio.{ Chunk, Scope }
maybeTypeInfo.contains(
genericTypeInfo(ListMap("T" -> TypeId.parse("scala.Int").asInstanceOf[TypeId.Nominal]))
),
capturedSchema.schema.asInstanceOf[Schema.Record[GenericRecordWithDefaultValue[Int]]].id == TypeId.parse(
"zio.schema.DeriveSpec.GenericRecordWithDefaultValue"
),
annotations.exists { a =>
a.isInstanceOf[fieldDefaultValue[_]] &&
a.asInstanceOf[fieldDefaultValue[Option[Int]]].value == None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ trait SchemaPlatformSpecific {
Schema[String].transformOrFail(
string =>
try {
Right(new java.net.URL(string))
Right(new java.net.URI(string).toURL)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sneaked that one in. The URL constructor is deprecated in Java 21+ and this is the recommended migration

} catch { case _: Exception => Left(s"Invalid URL: $string") },
url => Right(url.toString)
)
Expand Down
Loading