Skip to content

Commit 3f0f156

Browse files
committed
Make ν rewrites opt-in.
1 parent 45cc31d commit 3f0f156

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ scalacOptions in Test ++= {
4141

4242
scalacOptions in Test += "-Yrangepos"
4343

44+
scalacOptions in Test += "-P:kind-projector:forall=true"
45+
4446
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
4547
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v")
4648

src/main/scala/KindProjector.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,27 @@ class KindProjector(val global: Global) extends Plugin {
1616
val name = "kind-projector"
1717
val description = "Expand type lambda syntax"
1818
val components = new KindRewriter(this, global) :: Nil
19+
20+
var enableForall = false
21+
22+
override def processOptions(options: List[String], error: String => Unit): Unit = {
23+
24+
// enable ∀ rewrites if "forall=true" is present
25+
val (forallOpts, rest) = options partition { _.split("=")(0) == "forall" }
26+
enableForall = forallOpts.lastOption match {
27+
case Some(opt) =>
28+
opt.split("=").tail match {
29+
case Array("true") => true
30+
case _ => false
31+
}
32+
case None => false
33+
}
34+
35+
if(rest.nonEmpty) error(s"Unrecognized ${name} options: ${rest.mkString}")
36+
}
1937
}
2038

21-
class KindRewriter(plugin: Plugin, val global: Global)
39+
class KindRewriter(plugin: KindProjector, val global: Global)
2240
extends PluginComponent with Transform with TypingTransformers with TreeDSL {
2341

2442
import global._
@@ -192,7 +210,7 @@ class KindRewriter(plugin: Plugin, val global: Global)
192210
atPos(tree.pos.makeTransparent)(
193211
q"new $arrowType { def $methodName[$TParam]($name: $f[$TParam]): $g[$TParam] = $body }"
194212
)
195-
case PolyVal(targetType, methodName, tArgs, body) =>
213+
case PolyVal(targetType, methodName, tArgs, body) if plugin.enableForall =>
196214
atPos(tree.pos.makeTransparent)(tArgs match {
197215
case Nil =>
198216
val tParam = newTypeName(freshName("A"))

0 commit comments

Comments
 (0)