Skip to content

Commit 9c0e4d2

Browse files
committed
Add missing case for finding default getters
There are two modes for finding default getters. They depend on whether the receiver is defined or not. If the receiver is not defined we search the enclosing scopes instead. This fails if the method and the call are in different toplevel files, since the scopes of the two are not enclosing. But that should not matter since for toplevel definitions we do have a defined receiver, namely the synthetic enclosing object. Only for extension methods it happened that that object was referred to via a This reference instead of a TermRef. This is allowed in general but fell through a missing case in this instance. Fixes #12897
1 parent e7eb856 commit 9c0e4d2

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ object Applications {
210210
case Select(receiver, _) => receiver
211211
case mr => mr.tpe.normalizedPrefix match {
212212
case mr: TermRef => ref(mr)
213+
case mr: ThisType => singleton(mr)
213214
case mr =>
214215
if testOnly then
215216
// In this case it is safe to skolemize now; we will produce a stable prefix for the actual call.

tests/pos/i12897/A.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
package TestFoo
3+
extension (text : String) def foo(defaultArg : Boolean = true) : String = ""
4+
5+
//def foo(text : String) (defaultArg : Boolean = true) : String = ""

tests/pos/i12897/B.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
package TestFoo
3+
4+
val f = "123".foo() //error

0 commit comments

Comments
 (0)