Skip to content

Commit efab3af

Browse files
authored
Backport "Be still more careful when computing denotations of class parameters" (#16196)
Backports #16112
2 parents d25bd16 + d742bac commit efab3af

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ object Denotations {
10761076
def aggregate[T](f: SingleDenotation => T, g: (T, T) => T): T = f(this)
10771077

10781078
type AsSeenFromResult = SingleDenotation
1079+
10791080
protected def computeAsSeenFrom(pre: Type)(using Context): SingleDenotation = {
10801081
val symbol = this.symbol
10811082
val owner = this match {
@@ -1120,19 +1121,31 @@ object Denotations {
11201121
then this
11211122
else if symbol.isAllOf(ClassTypeParam) then
11221123
val arg = symbol.typeRef.argForParam(pre, widenAbstract = true)
1123-
if arg.exists then
1124-
// take the argument bounds, but intersect with the symbols bounds if
1125-
// this forces nothing and gives a non-empty type.
1126-
val newBounds =
1127-
if symbol.isCompleted && !symbol.info.containsLazyRefs then
1128-
val combined @ TypeBounds(lo, hi) = symbol.info.bounds & arg.bounds
1129-
if lo frozen_<:< hi then combined
1130-
else arg.bounds
1131-
else arg.bounds
1132-
derivedSingleDenotation(symbol, newBounds, pre)
1124+
if arg.exists
1125+
then derivedSingleDenotation(symbol, normalizedArgBounds(arg.bounds), pre)
11331126
else derived(symbol.info)
11341127
else derived(symbol.info)
11351128
}
1129+
1130+
/** The argument bounds, possibly intersected with the parameter's info TypeBounds,
1131+
* if the latter is not F-bounded and does not refer to other type parameters
1132+
* of the same class, and the intersection is provably nonempty.
1133+
*/
1134+
private def normalizedArgBounds(argBounds: TypeBounds)(using Context): TypeBounds =
1135+
if symbol.isCompleted && !hasBoundsDependingOnParamsOf(symbol.owner) then
1136+
val combined @ TypeBounds(lo, hi) = symbol.info.bounds & argBounds
1137+
if (lo frozen_<:< hi) then combined
1138+
else argBounds
1139+
else argBounds
1140+
1141+
private def hasBoundsDependingOnParamsOf(cls: Symbol)(using Context): Boolean =
1142+
val acc = new TypeAccumulator[Boolean]:
1143+
def apply(x: Boolean, tp: Type): Boolean = tp match
1144+
case _: LazyRef => true
1145+
case tp: TypeRef
1146+
if tp.symbol.isAllOf(ClassTypeParam) && tp.symbol.owner == cls => true
1147+
case _ => foldOver(x, tp)
1148+
acc(false, symbol.info)
11361149
}
11371150

11381151
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type) extends SingleDenotation(symbol, initInfo) {

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,6 @@ object Types {
442442
final def containsWildcardTypes(using Context) =
443443
existsPart(_.isInstanceOf[WildcardType], StopAt.Static, forceLazy = false)
444444

445-
/** Does this type contain LazyRef types? */
446-
final def containsLazyRefs(using Context) =
447-
val acc = new TypeAccumulator[Boolean]:
448-
def apply(x: Boolean, tp: Type): Boolean = tp match
449-
case _: LazyRef => true
450-
case _ => x || foldOver(x, tp)
451-
acc(false, this)
452-
453445
// ----- Higher-order combinators -----------------------------------
454446

455447
/** Returns true if there is a part of this type that satisfies predicate `p`.

tests/pos/i16105.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait SQLSyntaxSupport[A]
2+
3+
trait ResultNameSQLSyntaxProvider[S <: SQLSyntaxSupport[A], A]
4+
trait QuerySQLSyntaxProvider[S <: SQLSyntaxSupport[A], A]{
5+
def resultName: ResultNameSQLSyntaxProvider[S, A] = ???
6+
}
7+
8+
def include(syntaxProviders: QuerySQLSyntaxProvider[_, _]*) = {
9+
syntax(syntaxProviders.map(_.resultName): _*)
10+
}
11+
12+
def syntax(resultNames: ResultNameSQLSyntaxProvider[_, _]*) = ???

0 commit comments

Comments
 (0)