Skip to content

Commit 2201a64

Browse files
committed
Scala 2.13.0-RC1 compiler crash
1 parent 74990e4 commit 2201a64

File tree

5 files changed

+55
-203
lines changed

5 files changed

+55
-203
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package scalaz
2+
3+
sealed abstract class CofreeInstancesVersionSpecific0 {
4+
5+
implicit def cofreeEqual[F[_], A](implicit A0: Equal[A], F0: => Equal[F[Cofree[F, A]]]): Equal[Cofree[F, A]] =
6+
new CofreeEqual[F, A] {
7+
override def A = A0
8+
override lazy val F = F0
9+
}
10+
}
11+
12+
abstract class CofreeInstancesVersionSpecific extends CofreeInstancesVersionSpecific0 {
13+
14+
implicit def cofreeOrder[F[_], A](implicit A0: Order[A], F0: => Order[F[Cofree[F, A]]]): Order[Cofree[F, A]] =
15+
new Order[Cofree[F, A]] with CofreeEqual[F, A] {
16+
override lazy val F = F0
17+
override def A = A0
18+
override def order(x: Cofree[F, A], y: Cofree[F, A]) = {
19+
Monoid[Ordering].append(A.order(x.head, y.head), F0.order(x.tail, y.tail))
20+
}
21+
}
22+
}
23+
24+
private trait CofreeEqual[F[_], A] extends Equal[Cofree[F, A]] {
25+
protected[this] def A: Equal[A]
26+
protected[this] def F: Equal[F[Cofree[F, A]]]
27+
override final def equal(x: Cofree[F, A], y: Cofree[F, A]) = {
28+
A.equal(x.head, y.head) && F.equal(x.tail, y.tail)
29+
}
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package scalaz
2+
3+
abstract class CofreeInstancesVersionSpecific {
4+
5+
}

core/src/main/scala/scalaz/Cofree.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object Cofree extends CofreeInstances {
116116

117117
import Cofree.CofreeZip
118118

119-
sealed abstract class CofreeInstances4 {
119+
sealed abstract class CofreeInstances4 extends CofreeInstancesVersionSpecific {
120120
/** low priority `Foldable1` instance */
121121
implicit def cofreeFoldable[F[_]: Foldable]: Foldable1[Cofree[F, ?]] =
122122
new CofreeFoldable[F]{

project/build.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ object build {
139139

140140
lazy val standardSettings: Seq[Sett] = Def.settings(
141141
organization := "org.scalaz",
142+
Seq(Compile, Test).map { scope =>
143+
unmanagedSourceDirectories in scope += {
144+
val dir = Defaults.nameForSrc(scope.name)
145+
val base = ScalazCrossType.shared(baseDirectory.value, dir).getParentFile
146+
CrossVersion.partialVersion(scalaVersion.value) match {
147+
case Some((2, v)) if v >= 13 =>
148+
base / s"scala-2.13+"
149+
case _ =>
150+
base / s"scala-2.13-"
151+
}
152+
}
153+
},
142154
mappings in (Compile, packageSrc) ++= (managedSources in Compile).value.map{ f =>
143155
// https://github.com/sbt/sbt-buildinfo/blob/v0.7.0/src/main/scala/sbtbuildinfo/BuildInfoPlugin.scala#L58
144156
val buildInfoDir = "sbt-buildinfo"
@@ -162,7 +174,7 @@ object build {
162174
scalaCheckVersion := "1.14.0",
163175
scalacOptions ++= stdOptions ++ (CrossVersion.partialVersion(scalaVersion.value) match {
164176
case Some((2,11)) => Scala211_jvm_and_js_options
165-
case _ => Seq("-opt:l:method")
177+
case _ => Nil
166178
}),
167179
scalacOptions ++= PartialFunction.condOpt(CrossVersion.partialVersion(scalaVersion.value)) {
168180
case Some((2, v)) if v <= 12 =>
@@ -174,10 +186,7 @@ object build {
174186
scalacOptions ++= {
175187
CrossVersion.partialVersion(scalaVersion.value) match {
176188
case Some((2, v)) if v >= 12 =>
177-
Seq(
178-
"-opt:l:method,inline",
179-
"-opt-inline-from:scalaz.**"
180-
)
189+
Nil
181190

182191
case Some((2, 11)) =>
183192
Seq("-Xsource:2.12")
Lines changed: 5 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -1,203 +1,11 @@
11
package scalaz
22

3-
import scalaz.scalacheck.ScalazProperties
4-
import scalaz.scalacheck.ScalazProperties._
5-
import scalaz.scalacheck.ScalazArbitrary._
6-
import scalaz.scalacheck.ScalaCheckBinding._
7-
import std.AllInstances._
8-
import org.scalacheck.{Arbitrary, Cogen}
9-
import org.scalacheck.Prop.forAll
10-
import Cofree._
11-
import Cofree.CofreeZip
12-
import Isomorphism._
3+
import scalaz.std.anyVal._
4+
import scalaz.std.list._
5+
import scalaz.std.java.enum._
136

14-
object CofreeTest extends SpecLite {
7+
object CofreeTest {
158

16-
type CofreeLazyOption[A] = Cofree[LazyOption, A]
17-
type CofreeStream[A] = Cofree[Stream, A]
18-
type OneAndStream[A] = OneAnd[Stream, A]
19-
type OneAndList[A] = OneAnd[List, A]
20-
type CofreeOption[A] = Cofree[Option, A]
9+
implicitly[Equal[Cofree[List, Int]]]
2110

22-
implicit def cofreeEqual[F[_], A](implicit F: Eq1[F], A: Equal[A]): Equal[Cofree[F, A]] =
23-
Equal.equal{ (a, b) =>
24-
A.equal(a.head, b.head) && F.eq1(cofreeEqual[F, A]).equal(a.tail, b.tail)
25-
}
26-
27-
implicit def cofreeZipEqual[F[_]: Eq1, A: Equal]: Equal[CofreeZip[F, A]] =
28-
Tag.subst(cofreeEqual[F, A])
29-
30-
//needed to prevent SOE for testing with equality
31-
implicit def cofreeOptEquals[A](implicit e: Equal[A]): Equal[CofreeOption[A]] = new Equal[CofreeOption[A]] {
32-
override def equal(a: CofreeOption[A], b: CofreeOption[A]): Boolean = {
33-
def tr(a: CofreeOption[A], b: CofreeOption[A]): Boolean =
34-
(a.tail, b.tail) match {
35-
case (Some(at), Some(bt)) if (e.equal(a.head, b.head)) => tr(at, bt)
36-
case (None, None) if (e.equal(a.head, b.head)) => true
37-
case _ => false
38-
}
39-
tr(a,b)
40-
}
41-
}
42-
43-
val oneAndListCofreeOptionIso: OneAndList <~> CofreeOption =
44-
new IsoFunctorTemplate[OneAndList, CofreeOption] {
45-
def to[A](fa: OneAndList[A]) =
46-
Cofree.unfold(fa) {
47-
case OneAnd(a, h :: t) =>
48-
(a, Some(OneAnd(h, t)))
49-
case OneAnd(a, _) => (a, None)
50-
}
51-
def from[A](ga: CofreeOption[A]) =
52-
OneAnd(
53-
ga.head,
54-
ga.tail.map(s =>
55-
Foldable[CofreeOption].foldRight(s, List.empty[A])(_ :: _)
56-
).getOrElse(Nil)
57-
)
58-
}
59-
60-
val oneAndStreamCofreeLazyOptionIso: OneAndStream <~> CofreeLazyOption =
61-
new IsoFunctorTemplate[OneAndStream, CofreeLazyOption] {
62-
def to[A](fa: OneAndStream[A]) =
63-
Cofree.unfold(fa){
64-
case OneAnd(a, h #:: t) => (a, LazyOption.lazySome(OneAnd(h, t)))
65-
case OneAnd(a, _) => (a, LazyOption.lazyNone)
66-
}
67-
def from[A](fa: CofreeLazyOption[A]) =
68-
OneAnd(
69-
fa.head,
70-
fa.tail.map(s =>
71-
Foldable[CofreeLazyOption].foldRight(s, Stream.empty[A])(_ #:: _)
72-
).getOrElse(Stream.empty)
73-
)
74-
}
75-
76-
val treeCofreeStreamIso: Tree <~> CofreeStream =
77-
new IsoFunctorTemplate[Tree, CofreeStream] {
78-
def to[A](tree: Tree[A]): CofreeStream[A] =
79-
Cofree(tree.rootLabel, tree.subForest.map(to(_)))
80-
def from[A](c: CofreeStream[A]): Tree[A] =
81-
Tree.Node(c.head, c.tail.map(from(_)))
82-
}
83-
84-
implicit def CofreeLazyOptionArb[A: Arbitrary]: Arbitrary[CofreeLazyOption[A]] =
85-
Functor[Arbitrary].map(implicitly[Arbitrary[OneAndStream[A]]])(oneAndStreamCofreeLazyOptionIso.to(_))
86-
87-
implicit def CofreeStreamArb[A: Arbitrary]: Arbitrary[CofreeStream[A]] =
88-
Functor[Arbitrary].map(implicitly[Arbitrary[Tree[A]]])(treeCofreeStreamIso.to.apply)
89-
90-
implicit def CofreeLazyOptionCogen[A: Cogen]: Cogen[CofreeLazyOption[A]] =
91-
implicitly[Cogen[OneAndStream[A]]].contramap(oneAndStreamCofreeLazyOptionIso.from.apply)
92-
93-
implicit def CofreeStreamCogen[A: Cogen]: Cogen[CofreeStream[A]] =
94-
implicitly[Cogen[Tree[A]]].contramap(treeCofreeStreamIso.from.apply)
95-
96-
implicit def CofreeOptionCogen[A: Cogen]: Cogen[CofreeOption[A]] =
97-
implicitly[Cogen[OneAndList[A]]].contramap(oneAndListCofreeOptionIso.from.apply)
98-
99-
implicit def CofreeOptionArb[A: Arbitrary]: Arbitrary[CofreeOption[A]] = {
100-
import org.scalacheck.Arbitrary._
101-
import org.scalacheck.Gen
102-
val arb = Arbitrary { Gen.listOfN(20, implicitly[Arbitrary[A]].arbitrary ) }
103-
Functor[Arbitrary].map(arb){
104-
case h :: Nil => oneAndListCofreeOptionIso.to( OneAnd(h, Nil))
105-
case h :: t => oneAndListCofreeOptionIso.to( OneAnd(h, t) )
106-
}
107-
}
108-
109-
checkAll("CofreeLazyOption", comonad.laws[CofreeLazyOption])
110-
checkAll("CofreeLazyOption", traverse1.laws[CofreeLazyOption])
111-
checkAll("CofreeLazyOption", monad.laws[CofreeLazyOption])
112-
checkAll("CofreeLazyOption", equal.laws[CofreeLazyOption[Int]])
113-
114-
checkAll("CofreeStream", comonad.laws[CofreeStream])
115-
checkAll("CofreeStream", traverse1.laws[CofreeStream])
116-
checkAll("CofreeStream", monad.laws[CofreeStream])
117-
checkAll("CofreeStream", equal.laws[CofreeStream[Int]])
118-
119-
checkAll("CofreeOption", comonad.laws[CofreeOption])
120-
checkAll("CofreeOption", monad.laws[CofreeOption])
121-
122-
{
123-
type CofreeZipLazyOption[A] = CofreeZip[LazyOption, A]
124-
125-
implicit def CofreeZipLazyOptionArb[A: Arbitrary]: Arbitrary[CofreeZipLazyOption[A]] =
126-
Tags.Zip.subst(CofreeLazyOptionArb[A])
127-
128-
// Hack: avoid stack overflow because `Applicative[CofreeLazyOption].point` is infinite stream
129-
def CofreeZipLazyOptionEqual[A: Equal]: Equal[CofreeZipLazyOption[A]] =
130-
Equal.equalBy{ a =>
131-
val OneAnd(h, t) = oneAndStreamCofreeLazyOptionIso.from(Tag.unwrap(a))
132-
h -> t.take(1000)
133-
}
134-
135-
checkAll("CofreeZipLazyOption", applicative.laws[CofreeZipLazyOption](implicitly, implicitly, implicitly, CofreeZipLazyOptionEqual))
136-
}
137-
138-
{
139-
type CofreeZipStream[A] = CofreeZip[Stream, A]
140-
141-
implicit def CofreeZipStreamArb[A: Arbitrary]: Arbitrary[CofreeZipStream[A]] =
142-
Tags.Zip.subst(CofreeStreamArb[A])
143-
144-
checkAll("CofreeZipStream", ScalazProperties.apply.laws[CofreeZipStream])
145-
}
146-
147-
"no stack overflow Applicative[CofreeZip[IList, ?]]#point" in {
148-
val a = 1
149-
val b = Applicative[CofreeZip[IList, ?]].point(a)
150-
val size = 10
151-
Foldable[Cofree[IList, ?]].toStream(Tag.unwrap(b)).take(size) must_=== Stream.fill(size)(a)
152-
}
153-
154-
"Applicative[λ[α => CofreeZip[LazyOption, α]]] is Applicative[λ[α => Stream[α] @@ Zip]]" ! forAll{
155-
(a: OneAndStream[Int], b: OneAndStream[Int]) =>
156-
157-
import syntax.foldable._
158-
val f = (_: Int) + (_: Int)
159-
val h #:: t = Tag.unwrap(Applicative[λ[α => Stream[α] @@ Tags.Zip]].apply2(Tags.Zip[Stream[Int]](a.toStream), Tags.Zip[Stream[Int]](b.toStream))(f))
160-
161-
val aa = Tags.Zip(oneAndStreamCofreeLazyOptionIso.to(a))
162-
val bb = Tags.Zip(oneAndStreamCofreeLazyOptionIso.to(b))
163-
val y = Applicative[λ[α => CofreeZip[LazyOption, α]]].apply2(aa, bb)(f)
164-
OneAnd(h, t) must_=== oneAndStreamCofreeLazyOptionIso.from(Tag.unwrap(y))
165-
}
166-
167-
"no stack overflow unfoldC, mapBranching" in {
168-
import syntax.foldable._
169-
val n = 100
170-
val list = Cofree.unfoldC(1)(a => Option(a + 1)).mapBranching(NaturalTransformation.refl).toStream.take(n).toList
171-
list must_=== (1 to n).toList
172-
}
173-
174-
object instances{
175-
def comonad[F[_]: Functor] = Comonad[Cofree[F, ?]]
176-
def bind[F[_]: Plus: Functor] = Bind[Cofree[F, ?]]
177-
def monad[F[_]: PlusEmpty: Functor] = Monad[Cofree[F, ?]]
178-
def foldable1[F[_]: Foldable] = Foldable1[Cofree[F, ?]]
179-
def traverse1[F[_]: Traverse] = Traverse1[Cofree[F, ?]]
180-
181-
// checking absence of ambiguity
182-
def bind[F[_]: PlusEmpty: Functor] = Bind[Cofree[F, ?]]
183-
def bind[F[_]: PlusEmpty: Traverse] = Bind[Cofree[F, ?]]
184-
def functor[F[_]: Traverse] = Functor[Cofree[F, ?]]
185-
def functor[F[_]: Traverse1] = Functor[Cofree[F, ?]]
186-
def functor[F[_]: Plus: Functor] = Functor[Cofree[F, ?]]
187-
def functor[F[_]: PlusEmpty: Traverse] = Functor[Cofree[F, ?]]
188-
def functor[F[_]: PlusEmpty: Traverse1] = Functor[Cofree[F, ?]]
189-
def foldable1[F[_]: Traverse1] = Foldable1[Cofree[F, ?]]
190-
def traverse1[F[_]: Traverse1] = Traverse1[Cofree[F, ?]]
191-
192-
object zip{
193-
def functor[F[_]: Functor] = Functor[CofreeZip[F, ?]]
194-
def apply[F[_]: Apply] = Apply[CofreeZip[F, ?]]
195-
def applicative[F[_]: Applicative] = Applicative[CofreeZip[F, ?]]
196-
197-
// checking absence of ambiguity
198-
def functor[F[_]: Applicative] = Functor[CofreeZip[F, ?]]
199-
def apply[F[_]: Applicative] = Apply[CofreeZip[F, ?]]
200-
}
201-
202-
}
20311
}

0 commit comments

Comments
 (0)