Skip to content

Commit 1e04416

Browse files
committed
Fix fields as a selectable type member
The selectDynamic call could already have influenced type variables in the expected type before we wrap it in a cast. Need to pass in the right expected type to the typedDynamicSelect.
1 parent 5a1a6cd commit 1e04416

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
790790
if canDefineFurther(qual.tpe.widen) then
791791
return typedSelect(tree, pt, qual)
792792

793-
def dynamicSelect =
793+
def dynamicSelect(pt: Type) =
794794
val tree2 = cpy.Select(tree0)(untpd.TypedSplice(qual), selName)
795795
if pt.isInstanceOf[FunOrPolyProto] || pt == LhsProto then
796796
assignType(tree2, TryDynamicCallType)
@@ -800,7 +800,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
800800
// Otherwise, if the qualifier derives from class Dynamic, expand to a
801801
// dynamic dispatch using selectDynamic or applyDynamic
802802
if qual.tpe.derivesFrom(defn.DynamicClass) && selName.isTermName && !isDynamicExpansion(tree) then
803-
return dynamicSelect
803+
return dynamicSelect(pt)
804804

805805
// Otherwise, if the qualifier derives from class Selectable,
806806
// and the selector name matches one of the element of the `Fields` type member,
@@ -814,7 +814,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
814814
typr.println(i"try dyn select $qual, $selName, $fields")
815815
fields.find(_._1 == selName) match
816816
case Some((_, fieldType)) =>
817-
return dynamicSelect.cast(fieldType)
817+
return dynamicSelect(fieldType).ensureConforms(fieldType)
818818
case _ =>
819819

820820
// Otherwise, report an error

0 commit comments

Comments
 (0)