Skip to content

Commit d03d2f8

Browse files
Revert "Heal member-select on opaque reference" (#21340)
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.
2 parents 299c0b7 + 34ccc43 commit d03d2f8

File tree

4 files changed

+1
-50
lines changed

4 files changed

+1
-50
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
15961596
* Note: It would be legal to do the lifting also if M does not contain opaque types,
15971597
* but in this case the retries in tryLiftedToThis would be redundant.
15981598
*/
1599-
def liftToThis(tp: Type): Type = {
1599+
private def liftToThis(tp: Type): Type = {
16001600

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

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

-13
Original file line numberDiff line numberDiff line change
@@ -758,18 +758,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
758758
typedSelectWithAdapt(tree, pt, qual)
759759
else EmptyTree
760760

761-
// Otherwise, heal member selection on an opaque reference,
762-
// reusing the logic in TypeComparer.
763-
def tryLiftToThis() =
764-
val wtp = qual.tpe.widen
765-
val liftedTp = comparing(_.liftToThis(wtp))
766-
if liftedTp ne wtp then
767-
val qual1 = qual.cast(liftedTp)
768-
val tree1 = cpy.Select(tree0)(qual1, selName)
769-
val rawType1 = selectionType(tree1, qual1)
770-
tryType(tree1, qual1, rawType1)
771-
else EmptyTree
772-
773761
// Otherwise, try to expand a named tuple selection
774762
def tryNamedTupleSelection() =
775763
val namedTupleElems = qual.tpe.widenDealias.namedTupleElementTypes
@@ -881,7 +869,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
881869
tryType(tree, qual, rawType)
882870
.orElse(trySimplifyApply())
883871
.orElse(tryInstantiateTypeVar())
884-
.orElse(tryLiftToThis())
885872
.orElse(tryNamedTupleSelection())
886873
.orElse(trySmallGenericTuple(qual, withCast = true))
887874
.orElse(tryExt(tree, qual))

tests/pos/i19609.orig.scala

-12
This file was deleted.

tests/pos/i19609.scala

-24
This file was deleted.

0 commit comments

Comments
 (0)