Skip to content

Cannot infer parameter type with PolyFunction and PartialFunction #14309

Open
@nicolasstucki

Description

@nicolasstucki

Compiler version

3.1.0 2654b56

Minimized code

def f(f: [U] => Int ?=> PartialFunction[U, Unit]): Unit = f[Int](using 1)(2)

def test =
  f([X] => (x: Int) ?=> {
    case 3 =>
  })

  f {
    case 3 =>
  }

Output

-- [E081] Type Error: Bar.scala:6:4 --------------------------------------------
6 |    case 3 =>
  |    ^
  |    Missing parameter type
  |
  |    I could not infer the type of the parameter x$1 of expanded function:
  |    x$1 => 
  |      x$1 match 
  |        {
  |          case 3 => 
  |            <empty>
  |        }.
-- [E007] Type Mismatch Error: Bar.scala:7:3 -----------------------------------
7 |  })
  |   ^
  |   Found:    [X] => (Int) ?=> 
  |     <error Missing parameter type
  |
  |   I could not infer the type of the parameter x$1 of expanded function:
  |   x$1 => 
  |     x$1 match 
  |       {
  |         case 3 => 
  |           <empty>
  |       }.>
  |    => Unit
  |   Required: [U] => (Int) ?=> PartialFunction[U, Unit]

longer explanation available when compiling with `-explain`
-- [E081] Type Error: Bar.scala:10:4 -------------------------------------------
10 |    case 3 =>
   |    ^
   |   Missing parameter type
   |
   |   I could not infer the type of the parameter x$1 of expanded function:
   |   x$1 => 
   |     x$1 match 
   |       {
   |         case 3 => 
   |           <empty>
   |       }.
3 errors found

Expectation

These should compile. Starting with the non-eta-expanded version that would.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions