Skip to content

Revert "Drop phase.isTyper use in isLegalPrefix/asf" from Scala 3.6.4 #22653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
}
compareWild
case tp2: LazyRef =>
isBottom(tp1)
|| !tp2.evaluating && recur(tp1, tp2.ref)
isBottom(tp1) || !tp2.evaluating && recur(tp1, tp2.ref)
case CapturingType(_, _) =>
secondTry
case tp2: AnnotatedType if !tp2.isRefining =>
Expand Down Expand Up @@ -490,7 +489,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
// If `tp1` is in train of being evaluated, don't force it
// because that would cause an assertionError. Return false instead.
// See i859.scala for an example where we hit this case.
tp2.isAny
tp2.isRef(AnyClass, skipRefined = false)
|| !tp1.evaluating && recur(tp1.ref, tp2)
case AndType(tp11, tp12) =>
if tp11.stripTypeVar eq tp12.stripTypeVar then recur(tp11, tp2)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object TypeOps:
}

def isLegalPrefix(pre: Type)(using Context): Boolean =
pre.isStable
pre.isStable || !ctx.phase.isTyper

/** Implementation of Types#simplified */
def simplify(tp: Type, theMap: SimplifyMap | Null)(using Context): Type = {
Expand Down
29 changes: 16 additions & 13 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ object Types extends TypeUtils {
// ----- Tests -----------------------------------------------------

// // debug only: a unique identifier for a type
// val uniqId = { nextId = nextId + 1; nextId }
// if uniqId == 19555 then trace.dumpStack()
// val uniqId = {
// nextId = nextId + 1
// if (nextId == 19555)
// println("foo")
// nextId
// }

/** A cache indicating whether the type was still provisional, last time we checked */
@sharable private var mightBeProvisional = true
Expand Down Expand Up @@ -5578,25 +5582,24 @@ object Types extends TypeUtils {
}

def & (that: TypeBounds)(using Context): TypeBounds =
val lo1 = this.lo.stripLazyRef
val lo2 = that.lo.stripLazyRef
val hi1 = this.hi.stripLazyRef
val hi2 = that.hi.stripLazyRef

// This will try to preserve the FromJavaObjects type in upper bounds.
// For example, (? <: FromJavaObjects | Null) & (? <: Any),
// we want to get (? <: FromJavaObjects | Null) intead of (? <: Any),
// because we may check the result <:< (? <: Object | Null) later.
if hi1.containsFromJavaObject && (hi1 frozen_<:< hi2) && (lo2 frozen_<:< lo1) then
if this.hi.containsFromJavaObject
&& (this.hi frozen_<:< that.hi)
&& (that.lo frozen_<:< this.lo) then
// FromJavaObject in tp1.hi guarantees tp2.hi <:< tp1.hi
// prefer tp1 if FromJavaObject is in its hi
this
else if hi2.containsFromJavaObject && (hi2 frozen_<:< hi1) && (lo1 frozen_<:< lo2) then
else if that.hi.containsFromJavaObject
&& (that.hi frozen_<:< this.hi)
&& (this.lo frozen_<:< that.lo) then
// Similarly, prefer tp2 if FromJavaObject is in its hi
that
else if (lo1 frozen_<:< lo2) && (hi2 frozen_<:< hi1) then that
else if (lo2 frozen_<:< lo1) && (hi1 frozen_<:< hi2) then this
else TypeBounds(lo1 | lo2, hi1 & hi2)
else if (this.lo frozen_<:< that.lo) && (that.hi frozen_<:< this.hi) then that
else if (that.lo frozen_<:< this.lo) && (this.hi frozen_<:< that.hi) then this
else TypeBounds(this.lo | that.lo, this.hi & that.hi)

def | (that: TypeBounds)(using Context): TypeBounds =
if ((this.lo frozen_<:< that.lo) && (that.hi frozen_<:< this.hi)) this
Expand All @@ -5605,7 +5608,7 @@ object Types extends TypeUtils {

override def & (that: Type)(using Context): Type = that match {
case that: TypeBounds => this & that
case _ => super.&(that)
case _ => super.& (that)
}

override def | (that: Type)(using Context): Type = that match {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Recheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ abstract class Recheck extends Phase, SymTransformer:
sharpen: Denotation => Denotation)(using Context): Type =
if name.is(OuterSelectName) then tree.tpe
else
val pre = ta.maybeSkolemizePrefix(qualType, name)
//val pre = ta.maybeSkolemizePrefix(qualType, name)
val mbr =
sharpen(
qualType.findMember(name, pre,
qualType.findMember(name, qualType,
excluded = if tree.symbol.is(Private) then EmptyFlags else Private
)).suchThat(tree.symbol == _)
val newType = tree.tpe match
Expand Down
1 change: 0 additions & 1 deletion compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ t5031_2.scala
i16997.scala
i7414.scala
i17588.scala
i8300.scala
i9804.scala
i13433.scala
i16649-irrefutable.scala
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-custom-args/captures/lazylist.check
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylist.scala:41:42 -------------------------------------
41 | val ref4c: LazyList[Int]^{cap1, ref3} = ref4 // error
| ^^^^
| Found: (ref4 : lazylists.LazyList[Int]^{cap3, ref1, ref2})
| Found: (ref4 : lazylists.LazyList[Int]^{cap3, cap2, ref1, cap1})
| Required: lazylists.LazyList[Int]^{cap1, ref3}
|
| longer explanation available when compiling with `-explain`
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/6314-6.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
|object creation impossible, since def apply(fa: String): Int in trait XX in object Test3 is not defined
|(Note that
| parameter String in def apply(fa: String): Int in trait XX in object Test3 does not match
| parameter Test3.Bar[X & (X & Y)] in def apply(fa: Test3.Bar[X & YY.this.Foo]): Test3.Bar[Y & YY.this.Foo] in trait YY in object Test3
| parameter Test3.Bar[X & Object with Test3.YY {...}#Foo] in def apply(fa: Test3.Bar[X & YY.this.Foo]): Test3.Bar[Y & YY.this.Foo] in trait YY in object Test3
| )
-- Error: tests/neg/6314-6.scala:52:3 ----------------------------------------------------------------------------------
52 | (new YY {}).boom // error: object creation impossible
| ^
|object creation impossible, since def apply(fa: String): Int in trait XX in object Test4 is not defined
|(Note that
| parameter String in def apply(fa: String): Int in trait XX in object Test4 does not match
| parameter Test4.Bar[X & (X & Y)] in def apply(fa: Test4.Bar[X & YY.this.FooAlias]): Test4.Bar[Y & YY.this.FooAlias] in trait YY in object Test4
| parameter Test4.Bar[X & Object with Test4.YY {...}#FooAlias] in def apply(fa: Test4.Bar[X & YY.this.FooAlias]): Test4.Bar[Y & YY.this.FooAlias] in trait YY in object Test4
| )
2 changes: 1 addition & 1 deletion tests/neg/i6225.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
object O1 { // error: cannot be instantiated
object O1 {
type A[X] = X
opaque type T = A // error: opaque type alias must be fully applied
}
Expand Down
30 changes: 0 additions & 30 deletions tests/pos/i17222.2.scala

This file was deleted.

39 changes: 0 additions & 39 deletions tests/pos/i17222.3.scala

This file was deleted.

71 changes: 0 additions & 71 deletions tests/pos/i17222.4.scala

This file was deleted.

26 changes: 0 additions & 26 deletions tests/pos/i17222.5.scala

This file was deleted.

18 changes: 0 additions & 18 deletions tests/pos/i17222.8.scala

This file was deleted.

33 changes: 0 additions & 33 deletions tests/pos/i17222.scala

This file was deleted.

Loading