Skip to content

Commit

Permalink
Backport "Add default arguments to derived refined type" to LTS (#20687)
Browse files Browse the repository at this point in the history
Backports #18435 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 20, 2024
2 parents ddb9ae0 + 507eb90 commit e2a9516
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ class CheckCaptures extends Recheck, SymTransformer:
adaptTypeFun(actual, rinfo.resType, expected, covariant, insertBox,
ares1 =>
val rinfo1 = rinfo.derivedLambdaType(rinfo.paramNames, rinfo.paramInfos, ares1)
val actual1 = actual.derivedRefinedType(actual.parent, actual.refinedName, rinfo1)
val actual1 = actual.derivedRefinedType(refinedInfo = rinfo1)
actual1
)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ trait ConstraintHandling {
case tp: AndType =>
tp.derivedAndType(tp.tp1.hardenUnions, tp.tp2.hardenUnions)
case tp: RefinedType =>
tp.derivedRefinedType(tp.parent.hardenUnions, tp.refinedName, tp.refinedInfo)
tp.derivedRefinedType(parent = tp.parent.hardenUnions)
case tp: RecType =>
tp.rebind(tp.parent.hardenUnions)
case tp: HKTypeLambda =>
Expand Down
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 @@ -1731,7 +1731,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
private def fixRecs(anchor: SingletonType, tp: Type): Type = {
def fix(tp: Type): Type = tp.stripTypeVar match {
case tp: RecType => fix(tp.parent).substRecThis(tp, anchor)
case tp @ RefinedType(parent, rname, rinfo) => tp.derivedRefinedType(fix(parent), rname, rinfo)
case tp: RefinedType => tp.derivedRefinedType(parent = fix(tp.parent))
case tp: TypeParamRef => fixOrElse(bounds(tp).hi, tp)
case tp: TypeProxy => fixOrElse(tp.superType, tp)
case tp: AndType => tp.derivedAndType(fix(tp.tp1), fix(tp.tp2))
Expand Down
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ object Types {
case tp: AndType =>
tp.derivedAndType(tp.tp1.widenUnionWithoutNull, tp.tp2.widenUnionWithoutNull)
case tp: RefinedType =>
tp.derivedRefinedType(tp.parent.widenUnion, tp.refinedName, tp.refinedInfo)
tp.derivedRefinedType(parent = tp.parent.widenUnion)
case tp: RecType =>
tp.rebind(tp.parent.widenUnion)
case tp: HKTypeLambda =>
Expand Down Expand Up @@ -3152,7 +3152,9 @@ object Types {

def checkInst(using Context): this.type = this // debug hook

def derivedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)(using Context): Type =
final def derivedRefinedType
(parent: Type = this.parent, refinedName: Name = this.refinedName, refinedInfo: Type = this.refinedInfo)
(using Context): Type =
if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) this
else RefinedType(parent, refinedName, refinedInfo)

Expand Down Expand Up @@ -4056,7 +4058,7 @@ object Types {
case tp @ AppliedType(tycon, args) if defn.isFunctionNType(tp) =>
wrapConvertible(tp.derivedAppliedType(tycon, args.init :+ addInto(args.last)))
case tp @ defn.RefinedFunctionOf(rinfo) =>
wrapConvertible(tp.derivedRefinedType(tp.parent, tp.refinedName, addInto(rinfo)))
wrapConvertible(tp.derivedRefinedType(refinedInfo = addInto(rinfo)))
case tp: MethodOrPoly =>
tp.derivedLambdaType(resType = addInto(tp.resType))
case ExprType(resType) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val info1 = info.symbol.info
assert(info1.derivesFrom(defn.SingletonClass))
RefinedType(parent1, name, info1.mapReduceAnd(removeSingleton)(_ & _))
case info =>
tp.derivedRefinedType(parent1, name, info)
case _ =>
tp.derivedRefinedType(parent = parent1)
}
case tp @ AppliedType(tycon, args) =>
val tycon1 = tycon.safeDealias
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ trait Checking {
case tp @ AppliedType(tycon, args) =>
tp.derivedAppliedType(tycon, args.mapConserve(checkGoodBounds))
case tp: RefinedType =>
tp.derivedRefinedType(tp.parent, tp.refinedName, checkGoodBounds(tp.refinedInfo))
tp.derivedRefinedType(refinedInfo = checkGoodBounds(tp.refinedInfo))
case _ =>
tp
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ object Inferencing {
}
if tparams.isEmpty then tp else tp.derivedAppliedType(tycon, args1)
case tp: AndOrType => tp.derivedAndOrType(captureWildcards(tp.tp1), captureWildcards(tp.tp2))
case tp: RefinedType => tp.derivedRefinedType(captureWildcards(tp.parent), tp.refinedName, tp.refinedInfo)
case tp: RefinedType => tp.derivedRefinedType(parent = captureWildcards(tp.parent))
case tp: RecType => tp.derivedRecType(captureWildcards(tp.parent))
case tp: LazyRef => captureWildcards(tp.ref)
case tp: AnnotatedType => tp.derivedAnnotatedType(captureWildcards(tp.parent), tp.annot)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
def recur(handlers: SpecialHandlers): TreeWithErrors = handlers match
case (cls, handler) :: rest =>
def baseWithRefinements(tp: Type): Type = tp.dealias match
case tp @ RefinedType(parent, rname, rinfo) =>
tp.derivedRefinedType(baseWithRefinements(parent), rname, rinfo)
case tp: RefinedType =>
tp.derivedRefinedType(parent = baseWithRefinements(tp.parent))
case _ =>
tp.baseType(cls)
val base = baseWithRefinements(formal)
Expand Down

0 comments on commit e2a9516

Please sign in to comment.