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

Implemented is OpaqueType method #333

Open
wants to merge 1 commit into
base: scala3
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/core/interface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract class CaseClass[Typeclass[_], Type]
(val typeInfo: TypeInfo,
val isObject: Boolean,
val isValueClass: Boolean,
val isOpaqueType: Boolean,
val params: IArray[CaseClass.Param[Typeclass, Type]],
val annotations: IArray[Any],
val typeAnnotations: IArray[Any]) extends Serializable:
Expand Down
6 changes: 6 additions & 0 deletions src/core/macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import scala.quoted.*
object Macro:
inline def isObject[T]: Boolean = ${isObject[T]}
inline def isEnum[T]: Boolean = ${isEnum[T]}
inline def isOpaqueType[T]: Boolean = ${isOpaqueType[T]}
inline def anns[T]: List[Any] = ${anns[T]}
inline def typeAnns[T]: List[Any] = ${typeAnns[T]}
inline def paramAnns[T]: List[(String, List[Any])] = ${paramAnns[T]}
Expand All @@ -30,6 +31,11 @@ object Macro:

Expr(TypeRepr.of[T].typeSymbol.flags.is(Flags.Enum))

def isOpaqueType[T: Type](using Quotes): Expr[Boolean] =
import quotes.reflect.*

Expr(TypeRepr.of[T].typeSymbol.flags.is(Flags.Opaque))

def paramAnns[T: Type](using Quotes): Expr[List[(String, List[Any])]] =
import quotes.reflect.*

Expand Down
2 changes: 1 addition & 1 deletion src/core/magnolia.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait CommonDerivation[TypeClass[_]]:
val parameters = IArray(getParams[A, product.MirroredElemLabels, product.MirroredElemTypes](
paramAnns[A].to(Map), paramTypeAnns[A].to(Map), repeated[A].to(Map))*)

val caseClass = new CaseClass[Typeclass, A](typeInfo[A], isObject[A], isValueClass[A], parameters,
val caseClass = new CaseClass[Typeclass, A](typeInfo[A], isObject[A], isValueClass[A], isOpaqueType[A], parameters,
IArray(anns[A]*), IArray[Any](typeAnns[A]*)):

def construct[PType](makeParam: Param => PType)(using ClassTag[PType]): A =
Expand Down