File tree 3 files changed +60
-2
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +60
-2
lines changed Original file line number Diff line number Diff line change @@ -821,10 +821,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
821
821
822
822
// Otherwise, if the qualifier derives from class Selectable,
823
823
// and the selector name matches one of the element of the `Fields` type member,
824
- // and the selector is neither applied nor assigned to,
824
+ // and the selector is not assigned to,
825
825
// expand to a typed dynamic dispatch using selectDynamic wrapped in a cast
826
826
if qual.tpe.derivesFrom(defn.SelectableClass ) && ! isDynamicExpansion(tree)
827
- && ! pt. isInstanceOf [ FunOrPolyProto ] && pt != LhsProto
827
+ && pt != LhsProto
828
828
then
829
829
val pre = if ! TypeOps .isLegalPrefix(qual.tpe) then SkolemType (qual.tpe) else qual.tpe
830
830
val fieldsType = pre.select(tpnme.Fields ).dealias.simplified
Original file line number Diff line number Diff line change
1
+ import scala .language .experimental .namedTuples .*
2
+
3
+ class FromFields extends Selectable :
4
+ type Fields = (i : Int )
5
+ def selectDynamic (key : String ) =
6
+ List (1 , 2 , 3 )
7
+
8
+ trait FromRefs extends Selectable :
9
+ def selectDynamic (key : String ) =
10
+ List (1 , 2 , 3 )
11
+
12
+ def test (
13
+ fromFlds : FromFields ,
14
+ fromRefs : FromRefs { val i : Int }
15
+ ): Unit =
16
+ fromFlds.i(0 ) // error
17
+ fromRefs.i(0 ) // error
18
+
19
+ fromFlds.i.apply(0 ) // error
20
+ fromRefs.i.apply(0 ) // error
21
+
22
+ fromFlds.i[Int ](List (1 )) // error
23
+ fromRefs.i[Int ](List (1 )) // error
24
+
25
+ fromFlds.i(List (1 )) // error
26
+ fromRefs.i(List (1 )) // error
27
+
28
+ fromFlds.i.apply(List (1 )) // error
29
+ fromRefs.i.apply(List (1 )) // error
Original file line number Diff line number Diff line change
1
+ import scala .language .experimental .namedTuples .*
2
+
3
+ class FromFields extends Selectable :
4
+ type Fields = (xs : List [Int ], poly : [T ] => (x : List [T ]) => Option [T ])
5
+ def selectDynamic (key : String ) =
6
+ List (1 , 2 , 3 )
7
+
8
+ trait FromRefs extends Selectable :
9
+ def selectDynamic (key : String ) =
10
+ List (1 , 2 , 3 )
11
+
12
+ def test (
13
+ fromFlds : FromFields ,
14
+ fromRefs : FromRefs { val xs : List [Int ]; val poly : [T ] => (x : List [T ]) => Option [T ] }
15
+ ): Unit =
16
+ fromFlds.xs(0 )
17
+ fromRefs.xs(0 )
18
+
19
+ fromFlds.xs.apply(0 )
20
+ fromRefs.xs.apply(0 )
21
+
22
+ fromFlds.poly[Int ](List (1 )): Option [Int ]
23
+ fromRefs.poly[Int ](List (1 )): Option [Int ]
24
+
25
+ fromFlds.poly(List (1 ))
26
+ fromRefs.poly(List (1 ))
27
+
28
+ fromFlds.poly.apply(List (1 ))
29
+ fromRefs.poly.apply(List (1 ))
You can’t perform that action at this time.
0 commit comments