Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
geirolz opened this issue Feb 1, 2024 · 4 comments
Open

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

geirolz opened this issue Feb 1, 2024 · 4 comments

Comments

@geirolz
Copy link

geirolz commented Feb 1, 2024

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.

@geirolz geirolz added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 1, 2024
@bishabosha
Copy link
Member

this is definitely a bug, here is output with -Xprint:typer flag:

final lazy module val Test2: Test2 = new Test2()
    final module class Test2() extends Object() { this: Test2.type =>
      export Foo.{withDefaults as fooWithDefaults}
      final def fooWithDefaults(bar: String, baz: Int): Foo =
        Foo.withDefaults(bar, baz)
      final def withDefaults$default$1: String @uncheckedVariance =
        Foo.withDefaults$default$1
      final def withDefaults$default$2: Int @uncheckedVariance =
        Foo.withDefaults$default$2
    }

@bishabosha bishabosha self-assigned this Feb 1, 2024
@bishabosha bishabosha added area:export area:default-parameters and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 1, 2024
@lbialy
Copy link

lbialy commented Feb 1, 2024

We've noticed the same problem in Besom on Monday where we export methods from internals to the public API. Defaults are gone after the export, even method signature hint from PC shows there are no defaults.

@soronpo
Copy link
Contributor

soronpo commented Feb 1, 2024

So it seems export is currently dropping modifiers (like infix), annotations, and also default parameters.
When we are thinking about language feature interaction, we should really consider better coverage for future language improvements.

@som-snytt
Copy link
Contributor

Slightly related #17930 links to the recent fix for flags.

The PR is just for the bug in renaming.

Now that bishabosha is moving on from Scala Center, minions must step up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants