File tree 3 files changed +15
-2
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -818,14 +818,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
818
818
// and the selector is neither applied nor assigned to,
819
819
// expand to a typed dynamic dispatch using selectDynamic wrapped in a cast
820
820
if qual.tpe.derivesFrom(defn.SelectableClass ) && ! isDynamicExpansion(tree)
821
- && ! pt.isInstanceOf [FunOrPolyProto ] && pt != LhsProto
821
+ && ! pt.isInstanceOf [FunOrPolyProto ] && pt != LhsProto
822
822
then
823
823
val fieldsType = qual.tpe.select(tpnme.Fields ).dealias.simplified
824
824
val fields = fieldsType.namedTupleElementTypes
825
825
typr.println(i " try dyn select $qual, $selName, $fields" )
826
826
fields.find(_._1 == selName) match
827
827
case Some ((_, fieldType)) =>
828
- return dynamicSelect(fieldType).ensureConforms(fieldType)
828
+ val dynSelected = dynamicSelect(fieldType)
829
+ dynSelected match
830
+ case Apply (sel : Select , _) if ! sel.denot.symbol.exists =>
831
+ // Reject corner case where selectDynamic needs annother selectDynamic to be called. E.g. as in neg/unselectable-fields.scala.
832
+ report.error(i " Cannot use selectDynamic here since it it needs another selectDynamic to be invoked " , tree.srcPos)
833
+ case _ =>
834
+ return dynSelected.ensureConforms(fieldType)
829
835
case _ =>
830
836
831
837
// Otherwise, report an error
Original file line number Diff line number Diff line change
1
+ -- Error: tests/neg/unselectable-fields.scala:4:13 ---------------------------------------------------------------------
2
+ 4 |val _ = foo1.xyz // error
3
+ | ^^^^^^^^
4
+ | Cannot use selectDynamic here since it it needs another selectDynamic to be invoked
Original file line number Diff line number Diff line change 1
1
val foo1 = new Selectable :
2
2
type Fields = (xyz : Int )
3
3
def selectDynamic (name : String ): Any = 23
4
+ val _ = foo1.xyz // error
5
+
6
+
You can’t perform that action at this time.
0 commit comments