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

Backport "Fix default args lookup for given classes" to LTS #21084

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,20 @@ object Applications {
if (getterDenot.exists) qual.select(TermRef(qual.tpe, getterName, getterDenot))
else EmptyTree
if !meth.isClassConstructor then
selectGetter(receiver)
val res = selectGetter(receiver)
if res.isEmpty && meth.is(Given) then
val classSym = meth.info.finalResultType.typeSymbol
if classSym.isClass && classSym.isAllOf(Given | Synthetic) then
// `meth` is an implicit wrapper: the `given def` desugared from a
// `given C(...)` or `given C with ...` by `desugar#classDef`.
// Therefore, we can try to look for the default getters of the
// constructor of the `given class`. We find it via the `given
// def`'s result type. See #20088 and associated test cases.
val classRefTree = receiver.select(classSym)
val constructorSym = classSym.primaryConstructor.asTerm
findDefaultGetter(constructorSym, classRefTree, idx)
else res
else res
else
// default getters for class constructors are found in the companion object
val cls = meth.owner
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/20088.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait Foo
trait Bar

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

def Test = summon[Bar]
6 changes: 6 additions & 0 deletions tests/pos/20088b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait Foo
class Bar

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

def Test = summon[Bar]