Skip to content

Implementation restriction: polymorphic function literals must have a value parameter #15555

@Swoorup

Description

@Swoorup

Compiler version

3.1.3

Minimized code

enum CounterInput[Response]:
  case Inc extends CounterInput[Unit]
  case Dec extends CounterInput[Unit]
  case Get extends CounterInput[Int]

def counterBehaviorK[O]: (Int, CounterInput[O]) => (Int, O) =
  case (s, CounterInput.Inc) =>
    (s + 1, ())
  case (s, CounterInput.Dec) =>
    (s + 1, ())
  case (s, CounterInput.Get) =>
    (s, s)

// not sure how to pass this behavior parameter
def doSth[S, I[_]](behavior: [O] => (S, I[O]) => (S, O)) = println("Hi")

doSth[Int, CounterInput]([O] => counterBehaviorK[O]) // Implementation restriction: polymorphic function literals must have a value parameter
doSth[Int, CounterInput](counterBehaviorK)  // Also error

Scastie: https://scastie.scala-lang.org/7dElqAKNQme6XFWEYckzhA

Output

Implementation restriction: polymorphic function literals must have a value parameter

Expectation

Compiles successfully

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions