diff --git a/modules/core/src/main/scala/com/github/tarao/record4s/InternalMacros.scala b/modules/core/src/main/scala/com/github/tarao/record4s/InternalMacros.scala index c63548d..8cb8eb1 100644 --- a/modules/core/src/main/scala/com/github/tarao/record4s/InternalMacros.scala +++ b/modules/core/src/main/scala/com/github/tarao/record4s/InternalMacros.scala @@ -336,6 +336,23 @@ private[record4s] class InternalMacros(using (Expr.ofSeq(fields), tupledFieldTypes) } + def requireApply[C, T](context: Expr[C], method: Expr[String])( + block: => T, + ): T = { + method.asTerm match { + case Inlined(_, _, Literal(StringConstant(name))) if name == "apply" => + block + case Inlined(_, _, Literal(StringConstant(name))) => + errorAndAbort( + s"'${name}' is not a member of ${context.asTerm.tpe.widen.show} constructor", + ) + case _ => + errorAndAbort( + s"Invalid method invocation on ${context.asTerm.tpe.widen.show} constructor", + ) + } + } + def fieldSelectionsOf[S: Type]( schema: Schema, ): Seq[(String, String, Type[?])] = { @@ -399,26 +416,6 @@ private[record4s] class InternalMacros(using schema.fieldTypes.filterNot((label, _) => unselected.contains(label)) } - - def newMapRecord[R: Type](record: Expr[Iterable[(String, Any)]]): Expr[R] = - '{ new MapRecord(${ record }.toMap).asInstanceOf[R] } - - def requireApply[C, T](context: Expr[C], method: Expr[String])( - block: => T, - ): T = { - method.asTerm match { - case Inlined(_, _, Literal(StringConstant(name))) if name == "apply" => - block - case Inlined(_, _, Literal(StringConstant(name))) => - errorAndAbort( - s"'${name}' is not a member of ${context.asTerm.tpe.widen.show} constructor", - ) - case _ => - errorAndAbort( - s"Invalid method invocation on ${context.asTerm.tpe.widen.show} constructor", - ) - } - } } private[record4s] object InternalMacros { diff --git a/modules/core/src/main/scala/com/github/tarao/record4s/Macros.scala b/modules/core/src/main/scala/com/github/tarao/record4s/Macros.scala index 8453144..b41630c 100644 --- a/modules/core/src/main/scala/com/github/tarao/record4s/Macros.scala +++ b/modules/core/src/main/scala/com/github/tarao/record4s/Macros.scala @@ -22,9 +22,10 @@ object Macros { case '[tpe] => evidenceOf[Concat[R, tpe]] match { case '{ ${ _ }: Concat[R, tpe] { type Out = returnType } } => - newMapRecord[returnType]('{ - ${ rec }.toMap.concat(${ fields }) - }) + '{ + new MapRecord(${ rec }.toMap.concat(${ fields })) + .asInstanceOf[returnType] + } } } }