From 507eb90b36e64aabe0823b4264de08aa1b2cba09 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 20 Jun 2024 15:12:35 +0200 Subject: [PATCH] Add default arguments to `derivedRefinedType` [Cherry-picked ab9f88219c1901be22243d084843c322cfb079a7][modified] --- compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala | 2 +- .../src/dotty/tools/dotc/core/ConstraintHandling.scala | 2 +- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 2 +- compiler/src/dotty/tools/dotc/core/Types.scala | 8 +++++--- .../tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Inferencing.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Synthesizer.scala | 4 ++-- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala index e6287bb3db5d..e989574ee794 100644 --- a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala +++ b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala @@ -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 _ => diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index 0adf632b03e1..37bce69e008b 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -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 => diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 8dac1f95e1b1..1e86c5039c7d 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -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)) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index ad60fa460c9f..8b2749fc1254 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -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 => @@ -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) @@ -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) => diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index deb022d3c261..9fb696b23ef7 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 061266014615..93acc01d28ad 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -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 } diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 47d90a4ffcef..080048a9e91e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -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) diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index 1772155e54c7..d1307c794af4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -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)