Linear types in Scala
  • Scala 99.6%
  • Java 0.4%
Find a file
2026-06-29 17:07:06 -07:00
.github/workflows gha: lock ubuntu version, update actions versions (#118) 2025-02-05 05:53:21 -07:00
input/src/main/scala/fix Update sbt-scalafmt from 2.4.3 to 2.4.4 (#28) 2021-11-21 05:54:14 -07:00
library/src/main/java/com/earldouglas/linearscala Take a first crack at an implementation (#2) 2021-05-16 09:22:24 -07:00
plugin sbt-scalafix: 0.12.0 -> 0.12.1 (#97) 2024-06-02 03:56:05 -07:00
project sbt: 1.12.11 -> 1.12.13 (#172) 2026-06-29 17:07:06 -07:00
rules/src/main Use Term#toString on empty Symbol#displayName (#21) 2021-08-28 10:48:57 -07:00
tests/src/test/scala/fix sbt-scalafix: 0.10.4 -> 0.11.0 (#74) 2023-07-01 06:15:44 -07:00
.scalafmt.conf scalafmt: 3.11.0 -> 3.11.1 (#170) 2026-05-16 07:51:38 -07:00
build.sbt sbt-scalafix: 0.10.4 -> 0.11.0 (#74) 2023-07-01 06:15:44 -07:00
CONTRIBUTING.md Use an env var to set the version for publishing 2022-03-16 08:14:05 -07:00
LICENSE Add a local copy of the ISC license (#3) 2021-05-16 09:28:21 -07:00
README.md Use Scala syntax highlighting for *plugins.sbt* 2022-03-16 08:14:39 -07:00

Build Status Release Artifacts

linear-scala

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

Setup

project/plugins.sbt:

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

Usage

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
    x.value
}

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.

References

Linear Types