earldouglas / linear-scala   0.0.3

ISC License GitHub

Linear types in Scala

Scala versions: 2.11 2.12 2.13
sbt plugins: 1.0

Build Status Release Artifacts


linear-scala adds support for linear types in Scala via a custom Scalafix linter.



addSbtPlugin("com.earldouglas" % "sbt-linear-scala" % "0.0.3")


Mix in the Linear interface to prevent values from being under/over-used.

import com.earldouglas.linearscala.Linear

case class Box(value: Int) extends Linear

Scalafix finds values that are never used:

trait UnusedField {
  val box: Box = Box(42) // error: box is never used

trait UnusedParameter {
  def foo(x: Box, y: Box): Int = // error: y is never used

Scalafix also finds values that are used multiple times:

trait FieldUsedTwice {
  val box: Box = Box(42)
  println(box) // error: box is used twice
  println(box) // error: box is used twice

See the tests in input/src/main/scala/fix/ for more examples.


Linear Types