Skip to content

Commit 53791b0

Browse files
Revert "Heal member-select on opaque reference" (#21341)
This reverts commit 4443395. This reverts the behaviour changing part of #19730, which could make code that previously compiled, continue to compile but with a different runtime behaviour. Now, the code in question is very niche and esoteric, and effectively exploiting this opaque typing bug. So, we're happy to change the compiler to make this behaviour silently change, just not in a patch release. (Same as #21340, but for the LTS.)
2 parents 4eb7668 + 54aac8a commit 53791b0

File tree

4 files changed

+1
-50
lines changed

4 files changed

+1
-50
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
14941494
* Note: It would be legal to do the lifting also if M does not contain opaque types,
14951495
* but in this case the retries in tryLiftedToThis would be redundant.
14961496
*/
1497-
def liftToThis(tp: Type): Type = {
1497+
private def liftToThis(tp: Type): Type = {
14981498

14991499
def findEnclosingThis(moduleClass: Symbol, from: Symbol): Type =
15001500
if ((from.owner eq moduleClass) && from.isPackageObject && from.is(Opaque)) from.thisType

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -715,18 +715,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
715715
typedSelectWithAdapt(tree, pt, qual)
716716
else EmptyTree
717717

718-
// Otherwise, heal member selection on an opaque reference,
719-
// reusing the logic in TypeComparer.
720-
def tryLiftToThis() =
721-
val wtp = qual.tpe.widen
722-
val liftedTp = comparing(_.liftToThis(wtp))
723-
if liftedTp ne wtp then
724-
val qual1 = qual.cast(liftedTp)
725-
val tree1 = cpy.Select(tree0)(qual1, selName)
726-
val rawType1 = selectionType(tree1, qual1)
727-
tryType(tree1, qual1, rawType1)
728-
else EmptyTree
729-
730718
// Otherwise, map combinations of A *: B *: .... EmptyTuple with nesting levels <= 22
731719
// to the Tuple class of the right arity and select from that one
732720
def trySmallGenericTuple(qual: Tree, withCast: Boolean) =
@@ -793,7 +781,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
793781
tryType(tree, qual, rawType)
794782
.orElse(trySimplifyApply())
795783
.orElse(tryInstantiateTypeVar())
796-
.orElse(tryLiftToThis())
797784
.orElse(trySmallGenericTuple(qual, withCast = true))
798785
.orElse(tryExt(tree, qual))
799786
.orElse(tryGadt())

tests/pos/i19609.orig.scala

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/pos/i19609.scala

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)