E166: Cannot Extend Function

This error occurs when a class attempts to extend a context function type (a function type using ?=>).

Context function types are special types that represent functions with implicit parameters. Classes cannot directly extend these types because they have special semantics related to implicit resolution.


Example

class MyContextFunction extends (Int ?=> String)

Error

-- [E166] Syntax Error: example.scala:1:6 --------------------------------------
1 |class MyContextFunction extends (Int ?=> String)
  |      ^
  |      class MyContextFunction cannot extend a context function class

Solution

// Define a regular class with a method that returns the context function
class MyContextFunction {
  def apply: Int ?=> String = summon[Int].toString
}
// Or implement a regular function type
class MyFunction extends (Int => String) {
  def apply(x: Int): String = x.toString
}