Skip to content

Commit

Permalink
Make CrossVersion.Disabled stable
Browse files Browse the repository at this point in the history
Fixes sbt/sbt#4975

This makes `CrossVersion.Disabled` a stable identifier by reverting `final def` back to `final val`.

This is to fix Scala.JS build

```
[error] ScalaJSCrossVersion.scala:34:23: stable identifier required, but sbt.`package`.CrossVersion.Disabled found.
[error]     case CrossVersion.Disabled =>
[error]                       ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
```

### notes

- sbt#121 added `final val Disabled = sbt.librarymanagement.Disabled` but it was just a companion object
- sbt#280 actually made it `final val Disabled = sbt.librarymanagement.Disabled()`, but this broke Cat's build that was calling `CrossVersion.Disabled()`
- sbt#290 changed to `final def Disabled = sbt.librarymanagement.Disabled` and `object Disabled extends sbt.librarymanagement.Disabled`
- This changes back to `final val Disabled = sbt.librarymanagement.Disabled` (but because we changed the companion object in sbt#290 that's ok)
  • Loading branch information
eed3si9n committed Aug 22, 2019
1 parent c9ca41a commit c22cb34
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sealed class Disabled private () extends sbt.librarymanagement.CrossVersion() wi

}
object Disabled extends sbt.librarymanagement.Disabled {
def apply(): Disabled = new Disabled()
def apply(): Disabled = Disabled
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final case class ScalaVersion(full: String, binary: String)
private[librarymanagement] abstract class CrossVersionFunctions {

/** Compatibility with 0.13 */
final def Disabled = sbt.librarymanagement.Disabled
final val Disabled = sbt.librarymanagement.Disabled
final val Binary = sbt.librarymanagement.Binary
final val Constant = sbt.librarymanagement.Constant
final val Full = sbt.librarymanagement.Full
Expand Down
70 changes: 70 additions & 0 deletions core/src/test/scala/example/tests/CrossVersionCompatTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package example.tests

import sbt.librarymanagement.{ CrossVersion, Disabled }
import verify.BasicTestSuite

object CrossVersionCompatTest extends BasicTestSuite {
test("CrossVersion.Disabled is typed to be Disabled") {
assert(CrossVersion.Disabled match {
case _: Disabled => true
case _ => false
})
}

test("CrossVersion.Disabled functions as disabled") {
assert(CrossVersion(CrossVersion.disabled, "1.0.0", "1.0") == None)
assert(CrossVersion(CrossVersion.Disabled, "1.0.0", "1.0") == None)
}

test("CrossVersion.Disabled() is typed to be Disabled") {
assert(CrossVersion.Disabled() match {
case _: Disabled => true
case _ => false
})
}

test("CrossVersion.Disabled() functions as disabled") {
assert(CrossVersion(CrossVersion.disabled, "1.0.0", "1.0") == None)
assert(CrossVersion(CrossVersion.Disabled(), "1.0.0", "1.0") == None)
}

test("CrossVersion.Disabled is stable") {
assert(CrossVersion.Disabled match {
case CrossVersion.Disabled => true
case _ => false
})
}

test("sbt.librarymanagement.Disabled is typed to be Disabled") {
assert(Disabled match {
case _: Disabled => true
case _ => false
})
}

test("sbt.librarymanagement.Disabled is stable") {
assert(Disabled match {
case Disabled => true
case _ => false
})
}

test("sbt.librarymanagement.Disabled() is typed to be Disabled") {
assert(Disabled() match {
case _: Disabled => true
case _ => false
})
}

test("CrossVersion.disabled is sbt.librarymanagement.Disabled") {
assert(CrossVersion.disabled == Disabled)
}

test("CrossVersion.Disabled is sbt.librarymanagement.Disabled") {
assert(CrossVersion.Disabled == Disabled)
}

test("CrossVersion.Disabled() is sbt.librarymanagement.Disabled") {
assert(CrossVersion.Disabled() == Disabled)
}
}

0 comments on commit c22cb34

Please sign in to comment.