Skip to content

Parameter untupling can be prevented with indirection #21778

Closed as not planned
Closed as not planned
@coreywoodfield

Description

@coreywoodfield

Compiler version

3.3.4

Minimized code

doesn't work:

trait Foo {
  type T <: Tuple
  type Mapped = Tuple.Map[T, Option]

  def map[A](f: Mapped => A): Unit = ???
}
class Bar extends Foo {
  override type T = (Int, String)
  // doesn't compile
  map { (int, string) =>
    ()
  }
}

works:

trait Foo {
  type T <: Tuple
  
  def map[A](f: Tuple.Map[T, Option] => A): Unit = ???
}
class Bar extends Foo {
  override type T = (Int, String)
  // compiles fine
  map { (int, string) =>
    ()
  }
}

Output

-- [E086] Syntax Error: .../Test.scala:39:22 
39 |  map { (int, string) =>
   |        ^
   |        Wrong number of parameters, expected: 1
40 |    ()
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   | The function literal
   |
   |     (int, string) =>
   |   {
   |     ()
   |   }
   |
   | has 2 parameters. But the expected type
   |
   |     Bar.this.Map => Unit
   |
   | requires a function with 1 parameters.
    ----------------------------------------------------------------------------
one error found

Expectation

I expect parameter untupling to occur regardless of type indirection, as long as the type can be fully resolved where the parameter untupling should occur. Instead, parameter untupling does not always occur. I think the alias and the match type are both playing a role here: simply having two aliases that refer to a concrete tuple type (type T = (Int, String), type X = T) does not prevent parameter untupling

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions