Skip to content

Commit

Permalink
Merge branch 'master' into hkt-id-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 authored Apr 25, 2020
2 parents 4044e07 + ce32a3b commit c933bf3
Show file tree
Hide file tree
Showing 62 changed files with 1,136 additions and 1,650 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jdk:
scala:
- 2.11.12
- 2.12.11
- 2.13.1
- 2.13.2

env:
- {}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ resolvers ++= Seq(


Builds are available for Scala 2.11.x, 2.12.x and 2.13.x. The main line of development for
shapeless 2.3.3 is Scala 2.13.1.
shapeless 2.3.3 is Scala 2.13.2.

```scala
scalaVersion := "2.13.1"
scalaVersion := "2.13.2"

libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.3"
Expand All @@ -134,7 +134,7 @@ libraryDependencies ++= Seq(

For using snapshots of Shapeless you should add,
```scala
scalaVersion := "2.13.1"
scalaVersion := "2.13.2"

libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.4.0-SNAPSHOT"
Expand Down Expand Up @@ -164,8 +164,8 @@ releases][olderusage] on the shapeless wiki.

## Building shapeless

shapeless is built with SBT 1.2.8 or later, and its master branch is built with Scala 2.13.1 by default but also
cross-builds for 2.11.12 and 2.12.8.
shapeless is built with SBT 1.3.10 or later, and its master branch is built with Scala 2.13.2 by default but also
cross-builds for 2.11.12 and 2.12.11.

[namehashing]: https://github.com/sbt/sbt/issues/1640

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import sbtcrossproject.CrossProject

val Scala211 = "2.11.12"
val Scala212 = "2.12.11"
val Scala213 = "2.13.1"
val Scala213 = "2.13.2"

val isScalaNative = System.getenv("SCALA_NATIVE") != null
val hasScalaJsVersion = System.getenv("SCALA_JS_VERSION") != null
Expand Down
48 changes: 24 additions & 24 deletions core/jvm/src/test/scala/shapeless/serialization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ object SerializationTestDefns {

case class Box[T](t: T)

type K = HList.`'a, 'b, 'c`.T
type R = Record.`'a -> Int, 'b -> String, 'c -> Boolean`.T
type U = Union.`'a -> Int, 'b -> String, 'c -> Boolean`.T
type RM = Record.`'c -> Boolean, 'd -> Double`.T
type RM1 = Record.`'c -> Boolean, 'b -> String`.T
type RM2 = Record.`'b -> String, 'c -> Boolean`.T
type KA = Witness.`'a`.T
type KB = Witness.`'b`.T
type KC = Witness.`'c`.T
type K = HList.`"a", "b", "c"`.T
type R = Record.`"a" -> Int, "b" -> String, "c" -> Boolean`.T
type U = Union.`"a" -> Int, "b" -> String, "c" -> Boolean`.T
type RM = Record.`"c" -> Boolean, "d" -> Double`.T
type RM1 = Record.`"c" -> Boolean, "b" -> String`.T
type RM2 = Record.`"b" -> String, "c" -> Boolean`.T
type KA = Witness.`"a"`.T
type KB = Witness.`"b"`.T
type KC = Witness.`"c"`.T

sealed trait Tree[T]
case class Leaf[T](t: T) extends Tree[T]
Expand Down Expand Up @@ -285,7 +285,7 @@ class SerializationTests {
val cs = Coproduct[ISB]("foo")
val cb = Coproduct[ISB](true)

val r = Symbol("foo") ->> 23 :: Symbol("bar") ->> "foo" :: Symbol("baz") ->> true :: HNil
val r = "foo" ->> 23 :: "bar" ->> "foo" :: "baz" ->> true :: HNil

val prim = new Primary(42)
val sec = new Secondary("qux")
Expand All @@ -310,9 +310,9 @@ class SerializationTests {
type ISB = Int :+: String :+: Boolean :+: CNil
val cs = Coproduct[ISB]("foo")

val r = Symbol("foo") ->> 23 :: Symbol("bar") ->> "foo" :: Symbol("baz") ->> true :: HNil
val r = "foo" ->> 23 :: "bar" ->> "foo" :: "baz" ->> true :: HNil

type U = Union.`'foo -> Int, 'bar -> String, 'baz -> Boolean`.T
type U = Union.`"foo" -> Int, "bar" -> String, "baz" -> Boolean`.T
val u = Union[U](bar = "quux")

val t = (23, "foo", true)
Expand Down Expand Up @@ -353,7 +353,7 @@ class SerializationTests {
type LT = (Int, String) :: (Boolean, Double) :: (Char, Float) :: HNil
type AL = (Int => Double) :: (String => Char) :: (Boolean => Float) :: HNil
type I3 = Int :: Int :: Int :: HNil
val s = HList.`'a, "boo", 23, true`
val s = HList.`"a", "boo", 23, true`
type S = s.T

assertSerializable(IsHCons[L])
Expand Down Expand Up @@ -614,7 +614,7 @@ class SerializationTests {
type L = Int :+: String :+: Boolean :+: CNil
type LP = String :+: Boolean :+: Int :+: CNil
type BS = Boolean :+: String :+: CNil
val s = Coproduct.`'a, "boo", 23, true`
val s = Coproduct.`"a", "boo", 23, true`
type S = s.T

assertSerializable(Inject[L, Int])
Expand Down Expand Up @@ -950,8 +950,8 @@ class SerializationTests {
assertSerializable(Generic[(Int, String, Boolean)])
assertSerializable(Generic[Option[Int]])

assertSerializable(DefaultSymbolicLabelling[(Int, String, Boolean)])
assertSerializable(DefaultSymbolicLabelling[Option[Int]])
assertSerializable(Labelling[(Int, String, Boolean)])
assertSerializable(Labelling[Option[Int]])

assertSerializable(LabelledGeneric[(Int, String, Boolean)])
assertSerializable(LabelledGeneric[Option[Int]])
Expand Down Expand Up @@ -988,16 +988,16 @@ class SerializationTests {
// special cases of referenceSingletonTypeable,
// because symbols and objects preserve their
// identity during serialization/deserialization:
assertSerializable(Typeable[Witness.`'foo`.T])
assertSerializable(Typeable[Witness.`"foo"`.T])
assertSerializable(Typeable[Sing.type])
assertSerializable(Typeable[CaseObj.type])

// check that they indeed work
// correctly after deserialization:
val symInst = roundtrip(Typeable[Witness.`'foo`.T])
assertTrue(symInst.cast(Symbol("foo") : Any).isDefined)
val symInst = roundtrip(Typeable[Witness.`"foo"`.T])
assertTrue(symInst.cast("foo": Any).isDefined)
val objInst = roundtrip(Typeable[Sing.type])
assertTrue(objInst.cast(Sing : Any).isDefined)
assertTrue(objInst.cast(Sing: Any).isDefined)
val caseObjInst = roundtrip(Typeable[CaseObj.type])
assertTrue(caseObjInst.cast(CaseObj).isDefined)

Expand Down Expand Up @@ -1112,8 +1112,8 @@ class SerializationTests {
type OL = Option[Int] :: Option[String] :: Option[Boolean] :: HNil
type I3 = Int :: Int :: Int :: HNil
type IS = Int :: String :: HNil
type R = Record.`'a -> Int, 'b -> String, 'c -> Boolean`.T
type K = HList.`'a, 'b, 'c`.T
type R = Record.`"a" -> Int, "b" -> String, "c" -> Boolean`.T
type K = HList.`"a", "b", "c"`.T

assertSerializable(UnaryTCConstraint[HNil, Option])
assertSerializable(UnaryTCConstraint[OL, Option])
Expand Down Expand Up @@ -1190,9 +1190,9 @@ class SerializationTests {
val l8 = optic.hlistSelectLens[Int :: String :: Boolean :: HNil, String]
val l9 = optic.coproductSelectPrism[Int :+: String :+: Boolean :+: CNil, String]
val l10 = optic.hlistNthLens[Int :: String :: Boolean :: HNil, _1]
val l11 = optic.recordLens[Record.`'foo -> Int, 'bar -> String, 'baz -> Boolean`.T](Symbol("bar"))
val l11 = optic.recordLens[Record.`"foo" -> Int, "bar" -> String, "baz" -> Boolean`.T]("bar")
val l12 = optic[Tree[Int]].l.r.l.t
val l13 = optic[Node[Int]] >> Symbol("r")
val l13 = optic[Node[Int]] >> "r"
val l14 = optic[Node[Int]] >> _1

assertSerializable(l1)
Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/shapeless/annotation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ object TypeAnnotations {
implicit def materialize[A, T, Out <: HList]: Aux[A, T, Out] = macro AnnotationMacros.materializeTypeAnnotations[A, T, Out]
}

@macrocompat.bundle
class AnnotationMacros(val c: whitebox.Context) extends CaseClassMacros {
import c.universe._

Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/shapeless/cached.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class CachedMacrosState {
var cache = List.empty[(Any, Any)]
}

@macrocompat.bundle
class CachedMacros(override val c: whitebox.Context) extends LazyMacros(c) with OpenImplicitMacros {
import c.universe._
private val state = MacroState.getOrElseUpdate[CachedMacrosState](c.universe, new CachedMacrosState)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/shapeless/coproduct.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ object Coproduct extends Dynamic {
* type TwoTrueStr = Coproduct.`2, true, "str"`.T
* }}}
*/
def selectDynamic(tpeSelector: String): Any = macro LabelledMacros.coproductTypeImpl
def selectDynamic(tpeSelector: String): Any = macro LabelledMacros.coproductType

/** Allows to inject a runtime value of type `Any` in a `Coproduct` */
def runtimeInject[C <: Coproduct](x: Any)(implicit rinj: RuntimeInject[C]): Option[C] = rinj(x)
Expand Down
50 changes: 21 additions & 29 deletions core/src/main/scala/shapeless/default.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ trait Default[T] extends DepFn0 with Serializable {
object Default {
def apply[T](implicit default: Default[T]): Aux[T, default.Out] = default

// only kept to preserve binary compatibility
def mkDefault[T, Out0 <: HList](defaults: Out0): Aux[T, Out0] =
mkDefaultByName(defaults)

def mkDefaultByName[T, Out0 <: HList](defaults: => Out0): Aux[T, Out0] =
new Default[T] {
type Out = Out0
Expand All @@ -69,7 +65,7 @@ object Default {
*
* val default = Default.AsRecord[CC]
*
* // default.Out is Record.`'s -> String`.T
* // default.Out is Record.`"s" -> String`.T
* // default() returns Record(s = "b")
* }}}
*
Expand All @@ -93,41 +89,38 @@ object Default {

type Aux[L <: HList, Labels <: HList, Out0 <: HList] = Helper[L, Labels] { type Out = Out0 }

implicit def hnilHelper: Aux[HNil, HNil, HNil] =
implicit val hnilHelper: Aux[HNil, HNil, HNil] =
new Helper[HNil, HNil] {
type Out = HNil
def apply(l: HNil) = HNil
}

implicit def hconsSomeHelper[K <: Symbol, H, T <: HList, LabT <: HList, OutT <: HList]
(implicit
tailHelper: Aux[T, LabT, OutT]
): Aux[Some[H] :: T, K :: LabT, FieldType[K, H] :: OutT] =
implicit def hconsSomeHelper[K, H, T <: HList, LabT <: HList](
implicit tailHelper: Helper[T, LabT]
): Aux[Some[H] :: T, K :: LabT, FieldType[K, H] :: tailHelper.Out] =
new Helper[Some[H] :: T, K :: LabT] {
type Out = FieldType[K, H] :: OutT
def apply(l: Some[H] :: T) = field[K](l.head.get) :: tailHelper(l.tail)
type Out = FieldType[K, H] :: tailHelper.Out
def apply(l: Some[H] :: T): Out = field[K](l.head.get) :: tailHelper(l.tail)
}

implicit def hconsNoneHelper[K <: Symbol, T <: HList, LabT <: HList, OutT <: HList]
(implicit
tailHelper: Aux[T, LabT, OutT]
): Aux[None.type :: T, K :: LabT, OutT] =
implicit def hconsNoneHelper[K, T <: HList, LabT <: HList](
implicit tailHelper: Helper[T, LabT]
): Aux[None.type :: T, K :: LabT, tailHelper.Out] =
new Helper[None.type :: T, K :: LabT] {
type Out = OutT
def apply(l: None.type :: T) = tailHelper(l.tail)
type Out = tailHelper.Out
def apply(l: None.type :: T): Out = tailHelper(l.tail)
}
}

implicit def asRecord[T, Labels <: HList, Options <: HList, Rec <: HList]
(implicit
default: Default.Aux[T, Options],
labelling: DefaultSymbolicLabelling.Aux[T, Labels],
helper: Helper.Aux[Options, Labels, Rec]
): Aux[T, Rec] =
new AsRecord[T] {
type Out = Rec
def apply() = helper(default())
}
implicit def asRecord[T, Labels <: HList, Options <: HList](
implicit
default: Default.Aux[T, Options],
labelling: Labelling.Aux[T, Labels],
helper: Helper[Options, Labels]
): Aux[T, helper.Out] = new AsRecord[T] {
type Out = helper.Out
def apply(): Out = helper(default())
}
}


Expand Down Expand Up @@ -212,7 +205,6 @@ object Default {
}
}

@macrocompat.bundle
class DefaultMacros(val c: whitebox.Context) extends CaseClassMacros {
import c.universe._

Expand Down
Loading

0 comments on commit c933bf3

Please # to comment.