Skip to content

Commit

Permalink
Revert "Heal member-select on opaque reference" (#21340)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
WojciechMazur authored Aug 8, 2024
2 parents 299c0b7 + 34ccc43 commit d03d2f8
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 50 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
* Note: It would be legal to do the lifting also if M does not contain opaque types,
* but in this case the retries in tryLiftedToThis would be redundant.
*/
def liftToThis(tp: Type): Type = {
private def liftToThis(tp: Type): Type = {

def findEnclosingThis(moduleClass: Symbol, from: Symbol): Type =
if ((from.owner eq moduleClass) && from.isPackageObject && from.is(Opaque)) from.thisType
Expand Down
13 changes: 0 additions & 13 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -758,18 +758,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
typedSelectWithAdapt(tree, pt, qual)
else EmptyTree

// Otherwise, heal member selection on an opaque reference,
// reusing the logic in TypeComparer.
def tryLiftToThis() =
val wtp = qual.tpe.widen
val liftedTp = comparing(_.liftToThis(wtp))
if liftedTp ne wtp then
val qual1 = qual.cast(liftedTp)
val tree1 = cpy.Select(tree0)(qual1, selName)
val rawType1 = selectionType(tree1, qual1)
tryType(tree1, qual1, rawType1)
else EmptyTree

// Otherwise, try to expand a named tuple selection
def tryNamedTupleSelection() =
val namedTupleElems = qual.tpe.widenDealias.namedTupleElementTypes
Expand Down Expand Up @@ -881,7 +869,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
tryType(tree, qual, rawType)
.orElse(trySimplifyApply())
.orElse(tryInstantiateTypeVar())
.orElse(tryLiftToThis())
.orElse(tryNamedTupleSelection())
.orElse(trySmallGenericTuple(qual, withCast = true))
.orElse(tryExt(tree, qual))
Expand Down
12 changes: 0 additions & 12 deletions tests/pos/i19609.orig.scala

This file was deleted.

24 changes: 0 additions & 24 deletions tests/pos/i19609.scala

This file was deleted.

0 comments on commit d03d2f8

Please sign in to comment.