diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-03-29 12:20:31 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-04-04 23:33:41 -0700 |
commit | 28931c74ae9da49ffe88f6b5df90c3a70cc6814a (patch) | |
tree | 26922a9da01de518259284c99a627a14800ef9c7 | |
parent | fb514c8045df9eb36064aef05e50595287e9d9fa (diff) | |
download | magnolia-28931c74ae9da49ffe88f6b5df90c3a70cc6814a.tar.gz magnolia-28931c74ae9da49ffe88f6b5df90c3a70cc6814a.tar.bz2 magnolia-28931c74ae9da49ffe88f6b5df90c3a70cc6814a.zip |
Add option flag to parameters
-rw-r--r-- | build.sbt | 2 | ||||
-rw-r--r-- | core/shared/src/main/scala/interface.scala | 3 | ||||
-rw-r--r-- | core/shared/src/main/scala/magnolia.scala | 3 |
3 files changed, 7 insertions, 1 deletions
@@ -81,7 +81,7 @@ lazy val benchmarks = project lazy val buildSettings = Seq( organization := "com.propensive", name := "magnolia", - version := "0.7.1", + version := "0.7.2-SNAPSHOT", scalacOptions ++= Seq( "-deprecation", "-feature", diff --git a/core/shared/src/main/scala/interface.scala b/core/shared/src/main/scala/interface.scala index 6eea9f1..a61b557 100644 --- a/core/shared/src/main/scala/interface.scala +++ b/core/shared/src/main/scala/interface.scala @@ -63,6 +63,9 @@ trait Param[Typeclass[_], Type] { /** the name of the parameter */ def label: String + /** flag indicating a parameter of type scala.Option */ + def option: Boolean + /** flag indicating a repeated (aka. vararg) parameter * * For example, for a case class, diff --git a/core/shared/src/main/scala/magnolia.scala b/core/shared/src/main/scala/magnolia.scala index b61b7d7..7410776 100644 --- a/core/shared/src/main/scala/magnolia.scala +++ b/core/shared/src/main/scala/magnolia.scala @@ -299,6 +299,7 @@ object Magnolia { q"""$paramsVal($idx) = $magnoliaPkg.Magnolia.param[$typeConstructor, $genericType, $paramType]( ${param.name.decodedName.toString}, + ${param.returnType.typeConstructor =:= typeOf[Option[_]].typeConstructor}, $repeated, $ref, $defaultVal, @@ -446,6 +447,7 @@ object Magnolia { * This method is intended to be called only from code generated by the Magnolia macro, and * should not be called directly from users' code. */ def param[Tc[_], T, P](name: String, + isOption: Boolean, isRepeated: Boolean, typeclassParam: => Tc[P], defaultVal: => Option[P], @@ -454,6 +456,7 @@ object Magnolia { ): Param[Tc, T] = new Param[Tc, T] { type PType = P def label: String = name + def option: Boolean = isOption def repeated: Boolean = isRepeated def default: Option[PType] = defaultVal def typeclass: Tc[PType] = typeclassParam |