E207: Illegal Unroll Placement

This error occurs when the @unroll annotation is used in an invalid location. The @unroll annotation is an experimental feature that can only be applied to method parameters with default values.

The @unroll annotation is used to generate multiple overloaded versions of a method to maintain binary compatibility when adding new parameters with default values.

Example

import scala.annotation.unroll

@unroll
class UnrollClass

Error

-- [E207] Declaration Error: example.scala:4:6 ---------------------------------
4 |class UnrollClass
  |      ^
  |      @unroll is only allowed on a method parameter

Solution

Use the @unroll annotation only on method or constructor parameters that have default values:

import scala.annotation.unroll
import scala.annotation.experimental

@experimental
final class Unrolled(s: String, n: Int = 1, @unroll b: Boolean = true):
  def foo = s + n + b

Note that @unroll has additional restrictions:

  • The method must be effectively final (cannot be overridden)
  • The method cannot be local
  • For case classes, the annotation should be on the class constructor, not on generated methods

This is an experimental feature and requires the -experimental compiler flag.