Skip to content

Exporting a method with a different name drops the default parameters #19587

Closed
@geirolz

Description

@geirolz

Compiler version

Scala 3.3.1

Minimized code

case class Foo(bar: String, baz: Int)
object Foo:
  def withDefaults(bar: String = "", baz: Int = 0) = Foo(bar, baz)

object Test1:
  export Foo.withDefaults

object Test2:
  export Foo.withDefaults as fooWithDefaults

// this works
Test1.withDefaults("test1")

// this doesn't work
Test2.fooWithDefaults("test2")

Output

val res0: Foo = Foo(test1,0)
-- [E171] Type Error: ----------------------------------------------------------
1 |Test2.fooWithDefaults("test2")
  |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |missing argument for parameter baz of method fooWithDefaults in object Test2: (bar: String, baz: Int): Foo
1 error found

Expectation

Same behavior as Test1, renaming should have no effect on the default values of the methods.
I did't find any mention of this in the documentation so, I don't know if this is a design choice to avoid collisions and other problems or it's a bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions