Skip to content

Commit c0a0dec

Browse files
Backport "Use the unwidened type when casting structural calls" to LTS (#20693)
Backports #18527 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 05c4757 + d638138 commit c0a0dec

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -962,16 +962,11 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
962962
!tree.symbol.exists
963963
&& tree.isTerm
964964
&& hasRefinement(tree.qualifier.tpe)
965-
def loop(tree: Tree): Boolean = tree match
966-
case TypeApply(fun, _) =>
967-
loop(fun)
968-
case Apply(fun, _) =>
969-
loop(fun)
965+
funPart(tree) match
970966
case tree: Select =>
971967
isStructuralTermSelect(tree)
972968
case _ =>
973969
false
974-
loop(tree)
975970
}
976971

977972
/** Return a pair consisting of (supercall, rest)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ trait Dynamic {
235235
if ValueClasses.isDerivedValueClass(tpe.classSymbol) && qual.tpe <:< defn.ReflectSelectableTypeRef then
236236
val genericUnderlying = ValueClasses.valueClassUnbox(tpe.classSymbol.asClass)
237237
val underlying = tpe.select(genericUnderlying).widen.resultType
238-
New(tpe, tree.cast(underlying) :: Nil)
238+
New(tpe.widen, tree.cast(underlying) :: Nil)
239239
else
240240
tree
241241
maybeBoxed.cast(tpe)
242242

243243
fun.tpe.widen match {
244244
case tpe: ValueType =>
245-
structuralCall(nme.selectDynamic, Nil).maybeBoxingCast(tpe)
245+
structuralCall(nme.selectDynamic, Nil).maybeBoxingCast(fun.tpe.widenExpr)
246246

247247
case tpe: MethodType =>
248248
def isDependentMethod(tpe: Type): Boolean = tpe match {

presentation-compiler/src/main/dotty/tools/pc/HoverProvider.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ object HoverProvider:
181181
findRefinement(parent)
182182
case _ => None
183183

184-
val refTpe = sel.tpe.metalsDealias match
184+
val refTpe = sel.tpe.widen.metalsDealias match
185185
case r: RefinedType => Some(r)
186186
case t: (TermRef | TypeProxy) => Some(t.termSymbol.info.metalsDealias)
187187
case _ => None

tests/pos/i18263.orig.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sealed trait Scope
2+
sealed trait Domain extends Scope
3+
object Domain extends Domain
4+
5+
trait Baz[T]
6+
def baz(using ck: Scope): Baz[ck.type] = ???
7+
8+
class Foo extends scala.reflect.Selectable:
9+
type TScope = Domain
10+
final protected given TScope = Domain
11+
12+
object ID:
13+
val internal1 = new Foo:
14+
val ii = new Foo:
15+
val x = baz
16+
val z = internal1.ii.x //error

tests/pos/i18263.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
final class Bar
2+
final class Inv[T]
3+
class Foo extends scala.reflect.Selectable:
4+
type Boo = Bar
5+
final given boo1: Boo = new Bar
6+
7+
class Test:
8+
def mkInv(using bar: Bar): Inv[bar.type] = new Inv()
9+
10+
def test: Unit =
11+
val foo1 /* : Foo { val foo2: { z1 => Foo { val inv1: Inv[(z1.boo1 : z1.Boo)] }}} */ = new Foo:
12+
val foo2 /* : { z1 => Foo { val inv1: Inv[(z1.boo1 : z1.Boo)] }} */ = new Foo:
13+
val inv1 /* : Inv[( boo1 : Boo)] */ = mkInv /* (this.boo1) */
14+
val inv2 = foo1.foo2.inv1 // error
15+
()

0 commit comments

Comments
 (0)