Skip to content

Commit 5c8e7eb

Browse files
authored
Generate in Scala 3 macro typeId without type parameters (#694) (#702)
1 parent 3dc1748 commit 5c8e7eb

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private case class DeriveSchema()(using val ctx: Quotes) {
121121
val selfRefSymbol = Symbol.newVal(Symbol.spliceOwner, s"derivedSchema${stack.size}", TypeRepr.of[Schema[T]], Flags.Lazy, Symbol.noSymbol)
122122
val selfRef = Ref(selfRefSymbol)
123123

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

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

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

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

395395
val applied = if (cases.length <= 22) {
396396
val args = List(typeInfo) ++ cases :+ annotations

zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSpec.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ import zio.{ Chunk, Scope }
189189
maybeTypeInfo.contains(
190190
genericTypeInfo(ListMap("T" -> TypeId.parse("scala.Int").asInstanceOf[TypeId.Nominal]))
191191
),
192+
capturedSchema.schema.asInstanceOf[Schema.Record[GenericRecordWithDefaultValue[Int]]].id == TypeId.parse(
193+
"zio.schema.DeriveSpec.GenericRecordWithDefaultValue"
194+
),
192195
annotations.exists { a =>
193196
a.isInstanceOf[fieldDefaultValue[_]] &&
194197
a.asInstanceOf[fieldDefaultValue[Option[Int]]].value == None

zio-schema/jvm/src/main/scala/zio/schema/SchemaPlatformSpecific.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trait SchemaPlatformSpecific {
66
Schema[String].transformOrFail(
77
string =>
88
try {
9-
Right(new java.net.URL(string))
9+
Right(new java.net.URI(string).toURL)
1010
} catch { case _: Exception => Left(s"Invalid URL: $string") },
1111
url => Right(url.toString)
1212
)

0 commit comments

Comments
 (0)