Skip to content

Fail to infer parameter types of eta-expanded anonymous functions #3945

@biboudis

Description

@biboudis

In the following example I compose int with int.

object Test {
  def int[A](k: String => A)(s: String)(x: Int): A = ???

  // composing directly: ok in scalac, error in dotc
  val c: (String => String) => (String) => (Int) => (Int) => String = (int[Int => String] _).compose(int[String] _) 

  // unwrapping composition: ok in scalac, ok in dotc
  val q: (String => Int => String) => (String) => (Int) => (Int => String) = int[Int => String]
  val p: (String => String) => (String) => (Int) => String = int[String]
  val c2: (String => String) => (String) => (Int) => (Int) => String = q.compose(p) 
}

Doing it directly raises an inference error for both parameters of the anonymous function in dotty with the following error:

error missing parameter type

The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type: class dotty.tools.dotc.typer.ProtoTypes$AnyFunctionProto$
Missing type for parameter s

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions