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

Default given value doesn't work inside given definition #20088

Closed
t9dupuy opened this issue Apr 4, 2024 · 3 comments · Fixed by #20256
Closed

Default given value doesn't work inside given definition #20088

t9dupuy opened this issue Apr 4, 2024 · 3 comments · Fixed by #20256
Assignees
Milestone

Comments

@t9dupuy
Copy link

t9dupuy commented Apr 4, 2024

Compiler version

3.4.0

Minimized code

trait Foo
trait Bar

given (using foo: Foo = new {}): Bar with {}

summon[Bar]

Output

No given instance of type Bar was found for parameter x of method summon in object Predef.
I found:

    given_Bar(using )

But given instance given_Bar does not match type Bar.

Expectation

Minimized code should compile

Alternatively, compiler should prevent (or at least warn) user from giving context parameters default values inside given definition.

@t9dupuy t9dupuy added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 4, 2024
@Gedochao Gedochao added area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 5, 2024
@Gedochao Gedochao assigned nicolasstucki and mbovel and unassigned nicolasstucki Apr 5, 2024
@mbovel
Copy link
Member

mbovel commented Apr 8, 2024

Might be related to #19414. If we tweak lookup of implicits with default arguments, maybe that could also fix this issue.

@mbovel
Copy link
Member

mbovel commented Apr 24, 2024

While the reporting would be improved by the fix of #19414, the core issue is different; it's related to the designing of with when there are default arguments:

trait Foo
trait Bar
given wrong(using foo: Foo = new {}): Bar with {}
given good(using foo: Foo): Bar with {}
[[syntax trees at end of                     typer]] // tests/neg/20088.scala
package <empty> {
  ...
  final module class 20088$package() extends Object() {
    ...
    given class wrong(using foo: Foo) extends Object(), Bar { ... }
    final lazy module val wrong: wrong = new wrong()
    final module class wrong() extends AnyRef() { this: wrong.type => ... }
    final given def wrong(using foo: Foo): wrong = new wrong(using foo)()

    given class good(using foo: Foo) extends Object(), Bar { ... }
    final given def good(using foo: Foo): good = new good(using foo)()
  }
}

Seems to be the name of the generated companion object for wrong that clashes with the name of the implicit.

@mbovel
Copy link
Member

mbovel commented Apr 24, 2024

Actually, the name clash is not a problem. The issue is that the lookup for default argument fails: the default parameters getters are associated to the constructor, not to the generated implicit wrapper, and are not found.

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