Skip to content

Commit 115ea6e

Browse files
committed
0.3.0 release for 2.13 compat
2 parents b08e6a8 + f6abb9a commit 115ea6e

File tree

14 files changed

+237
-477
lines changed

14 files changed

+237
-477
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
target/
22
.idea/
3+
.bloop/
4+
.metals/

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A Scala compiler plugin to give patterns and for-comprehensions the love they de
88
## Getting started
99
The plugin is available on Maven Central.
1010
```sbt
11-
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.0-M4")
11+
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.0")
1212
```
1313
Supports Scala 2.11, 2.12, and 2.13.0-RC1
1414

Diff for: build.sbt

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import xerial.sbt.Sonatype._
2+
13
lazy val scala213 = "2.13.0-RC1"
24
lazy val scala212 = "2.12.8"
35
lazy val scala211 = "2.11.12"
6+
47
lazy val supportedScalaVersions = List(scala211, scala212, scala213)
58

69
ThisBuild / organization := "com.olegpy"
7-
ThisBuild / version := "0.2.4"
10+
ThisBuild / version := "0.3.0"
811
ThisBuild / licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
912
ThisBuild / homepage := Some(url("https://github.com/oleg-py/better-monadic-for"))
1013
ThisBuild / scalaVersion := scala212
@@ -14,7 +17,7 @@ val testSettings = Seq(
1417
"org.scalatest" %% "scalatest" % "3.0.8-RC2" % Test
1518
),
1619
Test / scalacOptions ++= {
17-
val jar = (plugin / Compile / packageBin).value
20+
val jar = (betterMonadicFor / Compile / packageBin).value
1821
Seq(s"-Xplugin:${jar.getAbsolutePath}", s"-Jdummy=${jar.lastModified}") // ensures recompile
1922
},
2023
Test / scalacOptions ++= {
@@ -27,23 +30,26 @@ val testSettings = Seq(
2730
)
2831

2932
lazy val root = (project in file("."))
30-
.aggregate(plugin, pluginTests, catsTests, pcplodTests)
33+
.aggregate(betterMonadicFor, pluginTests, catsTests, scalazTests, pcplodTests)
3134
.settings(
3235
crossScalaVersions := Nil,
3336
publish / skip := true
3437
)
3538

36-
lazy val plugin = (project in file("plugin"))
39+
lazy val betterMonadicFor = (project in file("better-monadic-for"))
3740
.settings(
3841
name := "better-monadic-for",
3942
crossScalaVersions := supportedScalaVersions,
4043
libraryDependencies ++= Seq(
4144
scalaOrganization.value % "scala-compiler" % scalaVersion.value,
42-
)
45+
),
46+
publishTo := sonatypePublishTo.value,
47+
publishMavenStyle := true,
48+
sonatypeProjectHosting := Some(GitHubHosting("oleg-py", "better-monadic-for", "[email protected]")),
4349
)
4450

4551
lazy val pluginTests = (project in file("plugin-tests"))
46-
.dependsOn(plugin)
52+
.dependsOn(betterMonadicFor)
4753
.settings(crossScalaVersions := supportedScalaVersions)
4854
.settings(testSettings)
4955

@@ -74,3 +80,15 @@ lazy val catsTests = (project in file("cats-tests"))
7480
)
7581
)
7682
.settings(testSettings)
83+
84+
85+
lazy val scalazTests = (project in file("scalaz-tests"))
86+
.dependsOn(pluginTests % "compile->compile;test->test")
87+
.settings(
88+
name := "scalaz-tests",
89+
crossScalaVersions := List(scala211, scala212),
90+
libraryDependencies ++= Seq(
91+
"org.scalaz" %% "scalaz-core" % "7.2.27" % Test,
92+
)
93+
)
94+
.settings(testSettings)

Diff for: cats-tests/src/test/scala/com/olegpy/bm4/CatsSyntaxTest.scala

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package com.olegpy.bm4
22

3+
import cats.Monad
34
import org.scalatest.FreeSpec
5+
import cats.implicits._
46

57
class CatsSyntaxTest extends FreeSpec {
6-
implicit val catsInstance: cats.FlatMap[MapCheck] = new cats.FlatMap[MapCheck] {
8+
implicit val mcCatsInstance: cats.FlatMap[MapCheck] = new cats.FlatMap[MapCheck] {
79
def flatMap[A, B](fa: MapCheck[A])(f: A => MapCheck[B]): MapCheck[B] = {
810
fa.flatMap(f)
911
}
1012

1113
def tailRecM[A, B](a: A)(f: A => MapCheck[Either[A, B]]): MapCheck[B] = {
12-
assert(false)
13-
null
14+
fail()
1415
}
1516
def map[A, B](fa: MapCheck[A])(f: A => B): MapCheck[B] = fa.map(f)
1617
}
18+
case class ImplicitTest(id: String)
19+
def typed[A](a: A) = ()
1720

1821
"works in generic context with extension methods of cats" in {
1922
import cats.syntax.all._
@@ -25,4 +28,19 @@ class CatsSyntaxTest extends FreeSpec {
2528

2629
sillyTest(new MapCheck(11), new MapCheck(42))
2730
}
31+
32+
"supports implicit0 in F-parametric methods" - {
33+
"in = bindings" in {
34+
def f[F[_]: Monad] =
35+
for {
36+
x <- 42.pure[F]
37+
_ <- "dummy".pure[F]
38+
implicit0(it: ImplicitTest) = ImplicitTest("eggs")
39+
str = "dummy"
40+
_ = typed[String](str)
41+
} yield assert(it eq implicitly[ImplicitTest])
42+
43+
f[Option]
44+
}
45+
}
2846
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.olegpy.bm4
2+
3+
import org.scalatest.FreeSpec
4+
5+
object CTTest {
6+
def foo[A]: Mo[A] = for {
7+
implicit0(a: A) <- Mo.delay(null.asInstanceOf[A])
8+
} yield implicitly[A]
9+
}
10+
11+
class TestImplicitPatterns extends FreeSpec {
12+
case class ImplicitTest(id: String)
13+
def typed[A](a: A) = ()
14+
case class ImplicitTest2(id: String)
15+
16+
// Make IDE happy
17+
// object implicit0 { def unapply[A](a: A) = Some(a) }
18+
19+
"Implicit patterns support" - {
20+
"for-comprehensions with plain types" - {
21+
"without type ascription" - {
22+
"as <- binding" in {
23+
for {
24+
x <- Option(42)
25+
implicit0(it: ImplicitTest) <- Option(ImplicitTest("eggs"))
26+
_ <- Option("dummy")
27+
_ = "dummy"
28+
_ = assert(implicitly[ImplicitTest] eq it)
29+
} yield "ok"
30+
}
31+
32+
"as = binding" - {
33+
"followed by multiple = bindings" in {
34+
for {
35+
x <- Option(42)
36+
_ <- Option("dummy")
37+
implicit0(it: ImplicitTest) = ImplicitTest("eggs")
38+
_ = "dummy"
39+
_ = assert(implicitly[ImplicitTest] eq it)
40+
} yield "ok"
41+
}
42+
43+
"followed by <- bindings then = bindings" in {
44+
for {
45+
x <- Option(42)
46+
_ <- Option("dummy")
47+
implicit0(it: ImplicitTest) = ImplicitTest("eggs")
48+
_ <- Option("dummy")
49+
_ = assert(implicitly[ImplicitTest] eq it)
50+
} yield "ok"
51+
}
52+
53+
"followed by = bindings then <- bindings" in {
54+
for {
55+
x <- Option(42)
56+
_ <- Option("dummy")
57+
implicit0(it: ImplicitTest) = ImplicitTest("eggs")
58+
_ = assert(implicitly[ImplicitTest] eq it)
59+
_ <- Option("dummy")
60+
} yield "ok"
61+
}
62+
63+
"with multiple implicit variables" - {
64+
"mixed bindings" in {
65+
for {
66+
_ <- Option("dummy")
67+
implicit0(it: ImplicitTest) = ImplicitTest("eggs")
68+
implicit0(it1: ImplicitTest2) <- Option(ImplicitTest2("42"))
69+
_ = assert(implicitly[ImplicitTest] eq it)
70+
_ = assert(implicitly[ImplicitTest2] eq it1)
71+
} yield "ok"
72+
}
73+
74+
"<- bindings" in {
75+
for {
76+
implicit0(it1: ImplicitTest2) <- Option(ImplicitTest2("42"))
77+
implicit0(it: ImplicitTest) <- Option(ImplicitTest("eggs"))
78+
_ = assert(implicitly[ImplicitTest] eq it)
79+
_ = assert(implicitly[ImplicitTest2] eq it1)
80+
} yield "ok"
81+
}
82+
}
83+
}
84+
}
85+
}
86+
87+
"match clauses" - {
88+
"without type ascription" in {
89+
(1, "foo", ImplicitTest("eggs")) match {
90+
case (_, "foo", implicit0(it: ImplicitTest)) =>
91+
assert(implicitly[ImplicitTest] eq it)
92+
}
93+
}
94+
}
95+
}
96+
}

Diff for: plugin-tests/src/test/scala/com/olegpy/bm4/TestNoTuples.scala

+62-62
Original file line numberDiff line numberDiff line change
@@ -32,69 +32,69 @@ class TestNoTuples extends FreeSpec {
3232
b3 = 42
3333
b4 = 42
3434
c <- new TupleChecker(6)
35-
} yield a + b0 + c + b4
36-
assert(r.a == 94)
37-
}
38-
39-
"for too many bindings" in {
40-
val r = for {
41-
_ <- new TupleChecker(4)
42-
a = 0
43-
b = 1
44-
c = 2
45-
d = 3
46-
e = 4
47-
f = 5
48-
g = 6
49-
h = 7
50-
i = 8
51-
j = 9
52-
k = 10
53-
l = 11
54-
m = 12
55-
n = 13
56-
o = 14
57-
p = 15
58-
q = 16
59-
r = 17
60-
s = 18
61-
t = 19
62-
u = 20
63-
v = 21
64-
w = 22
65-
x = 23
66-
y = 24
67-
z = 25
68-
a0 = "0"
69-
b0 = "1"
70-
c0 = "2"
71-
d0 = "3"
72-
e0 = "4"
73-
f0 = "5"
74-
g0 = "6"
75-
h0 = "7"
76-
i0 = "8"
77-
j0 = "9"
78-
k0 = "10"
79-
l0 = "11"
80-
m0 = "12"
81-
n0 = "13"
82-
o0 = "14"
83-
p0 = "15"
84-
q0 = "16"
85-
r0 = "17"
86-
s0 = "18"
87-
t0 = "19"
88-
u0 = "20"
89-
v0 = "21"
90-
w0 = "22"
91-
x0 = "23"
92-
y0 = "24"
93-
z0 = "25"
94-
} yield s"$a$z$z0"
95-
96-
assert(r.a == "02525")
35+
} yield a + b0 - b1 + b2 + c - b3 + b4
36+
assert(r.a == 52)
9737
}
38+
//
39+
// "for too many bindings" in {
40+
// val r = for {
41+
// _ <- new TupleChecker(4)
42+
// a = 0
43+
// b = 1
44+
// c = 2
45+
// d = 3
46+
// e = 4
47+
// f = 5
48+
// g = 6
49+
// h = 7
50+
// i = 8
51+
// j = 9
52+
// k = 10
53+
// l = 11
54+
// m = 12
55+
// n = 13
56+
// o = 14
57+
// p = 15
58+
// q = 16
59+
// r = 17
60+
// s = 18
61+
// t = 19
62+
// u = 20
63+
// v = 21
64+
// w = 22
65+
// x = 23
66+
// y = 24
67+
// z = 25
68+
// a0 = "0"
69+
// b0 = "1"
70+
// c0 = "2"
71+
// d0 = "3"
72+
// e0 = "4"
73+
// f0 = "5"
74+
// g0 = "6"
75+
// h0 = "7"
76+
// i0 = "8"
77+
// j0 = "9"
78+
// k0 = "10"
79+
// l0 = "11"
80+
// m0 = "12"
81+
// n0 = "13"
82+
// o0 = "14"
83+
// p0 = "15"
84+
// q0 = "16"
85+
// r0 = "17"
86+
// s0 = "18"
87+
// t0 = "19"
88+
// u0 = "20"
89+
// v0 = "21"
90+
// w0 = "22"
91+
// x0 = "23"
92+
// y0 = "24"
93+
// z0 = "25"
94+
// } yield s"$a$z$z0"
95+
//
96+
// assert(r.a == "02525")
97+
// }
9898

9999
"for Either in 2.11" in {
100100
def mkRight(a: Int): Either[String, Int] = Right(a)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.olegpy.bm4
2+
3+
// Test for issue #12
4+
object TestUnused extends App{
5+
for {
6+
_ <- Option(()) //parameter value x$5 in value $anonfun is never used
7+
_ = 0
8+
} yield ()
9+
}

Diff for: plugin/src/main/resources/scalac-plugin.xml

-4
This file was deleted.

0 commit comments

Comments
 (0)