Skip to content

Commit 779a382

Browse files
Reuse typed prefix for applyDynamic and applyDynamicNamed (#16552)
Fixes #16544
2 parents 0555491 + f670d71 commit 779a382

File tree

5 files changed

+200
-1
lines changed

5 files changed

+200
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,10 @@ trait Applications extends Compatibility {
10021002
case TypeApply(fun, _) => !fun.isInstanceOf[Select]
10031003
case _ => false
10041004
}
1005-
typedDynamicApply(tree, isInsertedApply, pt)
1005+
val tree1 = fun1 match
1006+
case Select(_, nme.apply) => tree
1007+
case _ => untpd.Apply(fun1, tree.args)
1008+
typedDynamicApply(tree1, isInsertedApply, pt)
10061009
case _ =>
10071010
if (originalProto.isDropped) fun1
10081011
else if (fun1.symbol == defn.Compiletime_summonFrom)

tests/pos/i16544a.scala

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import scala.language.dynamics
2+
3+
object Foo extends Dynamic:
4+
def applyDynamic(name: String)(): Foo.type = this
5+
6+
object Test:
7+
def test(): Foo.type =
8+
Foo.xxx()
9+
.xxx()
10+
.xxx()
11+
.xxx()
12+
.xxx()
13+
.xxx()
14+
.xxx()
15+
.xxx()
16+
.xxx()
17+
.xxx()
18+
.xxx()
19+
.xxx()
20+
.xxx()
21+
.xxx()
22+
.xxx()
23+
.xxx()
24+
.xxx()
25+
.xxx()
26+
.xxx()
27+
.xxx()
28+
.xxx()
29+
.xxx()
30+
.xxx()
31+
.xxx()
32+
.xxx()
33+
.xxx()
34+
.xxx()
35+
.xxx()
36+
.xxx()
37+
.xxx()
38+
.xxx()
39+
.xxx()
40+
.xxx()
41+
.xxx()
42+
.xxx()
43+
.xxx()
44+
.xxx()
45+
.xxx()
46+
.xxx()
47+
.xxx()
48+
.xxx()
49+
.xxx()

tests/pos/i16544b.scala

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import scala.language.dynamics
2+
3+
object Foo extends Dynamic:
4+
def applyDynamicNamed(name: String)(args: (String, Int)): Foo.type = this
5+
6+
object Test:
7+
def test(): Foo.type =
8+
Foo.xxx(a = 1)
9+
.xxx(a = 1)
10+
.xxx(a = 1)
11+
.xxx(a = 1)
12+
.xxx(a = 1)
13+
.xxx(a = 1)
14+
.xxx(a = 1)
15+
.xxx(a = 1)
16+
.xxx(a = 1)
17+
.xxx(a = 1)
18+
.xxx(a = 1)
19+
.xxx(a = 1)
20+
.xxx(a = 1)
21+
.xxx(a = 1)
22+
.xxx(a = 1)
23+
.xxx(a = 1)
24+
.xxx(a = 1)
25+
.xxx(a = 1)
26+
.xxx(a = 1)
27+
.xxx(a = 1)
28+
.xxx(a = 1)
29+
.xxx(a = 1)
30+
.xxx(a = 1)
31+
.xxx(a = 1)
32+
.xxx(a = 1)
33+
.xxx(a = 1)
34+
.xxx(a = 1)
35+
.xxx(a = 1)
36+
.xxx(a = 1)
37+
.xxx(a = 1)
38+
.xxx(a = 1)
39+
.xxx(a = 1)
40+
.xxx(a = 1)
41+
.xxx(a = 1)
42+
.xxx(a = 1)
43+
.xxx(a = 1)
44+
.xxx(a = 1)
45+
.xxx(a = 1)
46+
.xxx(a = 1)
47+
.xxx(a = 1)
48+
.xxx(a = 1)
49+
.xxx(a = 1)

tests/pos/i16544c.scala

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import scala.language.dynamics
2+
3+
object Foo extends Dynamic:
4+
def selectDynamic(name: String): Foo.type = this
5+
6+
object Test:
7+
def test(): Foo.type =
8+
Foo.xxx
9+
.xxx
10+
.xxx
11+
.xxx
12+
.xxx
13+
.xxx
14+
.xxx
15+
.xxx
16+
.xxx
17+
.xxx
18+
.xxx
19+
.xxx
20+
.xxx
21+
.xxx
22+
.xxx
23+
.xxx
24+
.xxx
25+
.xxx
26+
.xxx
27+
.xxx
28+
.xxx
29+
.xxx
30+
.xxx
31+
.xxx
32+
.xxx
33+
.xxx
34+
.xxx
35+
.xxx
36+
.xxx
37+
.xxx
38+
.xxx
39+
.xxx
40+
.xxx
41+
.xxx
42+
.xxx
43+
.xxx
44+
.xxx
45+
.xxx
46+
.xxx
47+
.xxx
48+
.xxx
49+
.xxx

tests/pos/i16544d.scala

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import scala.language.dynamics
2+
3+
object Foo extends Dynamic:
4+
def applyDynamic(name: String)(): Foo.type = this
5+
def applyDynamicNamed(name: String)(args: (String, Int)): Foo.type = this
6+
def selectDynamic(name: String): Foo.type = this
7+
8+
object Test:
9+
def test(): Foo.type =
10+
Foo.xxx
11+
.xxx()
12+
.xxx(a = 1)
13+
.xxx
14+
.xxx()
15+
.xxx(a = 1)
16+
.xxx
17+
.xxx()
18+
.xxx(a = 1)
19+
.xxx
20+
.xxx()
21+
.xxx(a = 1)
22+
.xxx
23+
.xxx()
24+
.xxx(a = 1)
25+
.xxx
26+
.xxx()
27+
.xxx(a = 1)
28+
.xxx
29+
.xxx()
30+
.xxx(a = 1)
31+
.xxx
32+
.xxx()
33+
.xxx(a = 1)
34+
.xxx
35+
.xxx()
36+
.xxx(a = 1)
37+
.xxx
38+
.xxx()
39+
.xxx(a = 1)
40+
.xxx
41+
.xxx()
42+
.xxx(a = 1)
43+
.xxx
44+
.xxx()
45+
.xxx(a = 1)
46+
.xxx
47+
.xxx()
48+
.xxx(a = 1)
49+
.xxx

0 commit comments

Comments
 (0)