Skip to content

Commit 2be96cf

Browse files
authored
Add default arguments to derived refined type (#18435)
2 parents f859640 + ab9f882 commit 2be96cf

File tree

8 files changed

+17
-15
lines changed

8 files changed

+17
-15
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class CheckCaptures extends Recheck, SymTransformer:
369369
case _ =>
370370
val t1 = t match
371371
case t @ defn.RefinedFunctionOf(rinfo: MethodType) =>
372-
t.derivedRefinedType(t.parent, t.refinedName, this(rinfo))
372+
t.derivedRefinedType(refinedInfo = this(rinfo))
373373
case _ =>
374374
mapOver(t)
375375
if variance > 0 then t1
@@ -948,7 +948,7 @@ class CheckCaptures extends Recheck, SymTransformer:
948948
adaptTypeFun(actual, rinfo.resType, expected, covariant, insertBox,
949949
ares1 =>
950950
val rinfo1 = rinfo.derivedLambdaType(rinfo.paramNames, rinfo.paramInfos, ares1)
951-
val actual1 = actual.derivedRefinedType(actual.parent, actual.refinedName, rinfo1)
951+
val actual1 = actual.derivedRefinedType(refinedInfo = rinfo1)
952952
actual1
953953
)
954954
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ trait ConstraintHandling {
689689
case tp: AndType =>
690690
tp.derivedAndType(tp.tp1.hardenUnions, tp.tp2.hardenUnions)
691691
case tp: RefinedType =>
692-
tp.derivedRefinedType(tp.parent.hardenUnions, tp.refinedName, tp.refinedInfo)
692+
tp.derivedRefinedType(parent = tp.parent.hardenUnions)
693693
case tp: RecType =>
694694
tp.rebind(tp.parent.hardenUnions)
695695
case tp: HKTypeLambda =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
18241824
private def fixRecs(anchor: SingletonType, tp: Type): Type = {
18251825
def fix(tp: Type): Type = tp.stripTypeVar match {
18261826
case tp: RecType => fix(tp.parent).substRecThis(tp, anchor)
1827-
case tp @ RefinedType(parent, rname, rinfo) => tp.derivedRefinedType(fix(parent), rname, rinfo)
1827+
case tp: RefinedType => tp.derivedRefinedType(parent = fix(tp.parent))
18281828
case tp: TypeParamRef => fixOrElse(bounds(tp).hi, tp)
18291829
case tp: TypeProxy => fixOrElse(tp.superType, tp)
18301830
case tp: AndType => tp.derivedAndType(fix(tp.tp1), fix(tp.tp2))

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ object Types {
13601360
case tp: AndType =>
13611361
tp.derivedAndType(tp.tp1.widenUnionWithoutNull, tp.tp2.widenUnionWithoutNull)
13621362
case tp: RefinedType =>
1363-
tp.derivedRefinedType(tp.parent.widenUnion, tp.refinedName, tp.refinedInfo)
1363+
tp.derivedRefinedType(parent = tp.parent.widenUnion)
13641364
case tp: RecType =>
13651365
tp.rebind(tp.parent.widenUnion)
13661366
case tp: HKTypeLambda =>
@@ -3226,7 +3226,9 @@ object Types {
32263226

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

3229-
def derivedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)(using Context): Type =
3229+
final def derivedRefinedType
3230+
(parent: Type = this.parent, refinedName: Name = this.refinedName, refinedInfo: Type = this.refinedInfo)
3231+
(using Context): Type =
32303232
if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) this
32313233
else RefinedType(parent, refinedName, refinedInfo)
32323234

@@ -4130,7 +4132,7 @@ object Types {
41304132
case tp @ AppliedType(tycon, args) if defn.isFunctionNType(tp) =>
41314133
wrapConvertible(tp.derivedAppliedType(tycon, args.init :+ addInto(args.last)))
41324134
case tp @ defn.RefinedFunctionOf(rinfo) =>
4133-
wrapConvertible(tp.derivedRefinedType(tp.parent, tp.refinedName, addInto(rinfo)))
4135+
wrapConvertible(tp.derivedRefinedType(refinedInfo = addInto(rinfo)))
41344136
case tp: MethodOrPoly =>
41354137
tp.derivedLambdaType(resType = addInto(tp.resType))
41364138
case ExprType(resType) =>
@@ -5631,8 +5633,8 @@ object Types {
56315633
else hi
56325634
case (arg, _) => arg
56335635
tp.derivedAppliedType(tycon, args1)
5634-
case tp @ RefinedType(parent, name, info) =>
5635-
tp.derivedRefinedType(approxWildcardArgs(parent), name, info)
5636+
case tp: RefinedType =>
5637+
tp.derivedRefinedType(approxWildcardArgs(tp.parent))
56365638
case _ =>
56375639
tp
56385640
approxWildcardArgs(tp)

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
734734
val info1 = info.symbol.info
735735
assert(info1.derivesFrom(defn.SingletonClass))
736736
RefinedType(parent1, name, info1.mapReduceAnd(removeSingleton)(_ & _))
737-
case info =>
738-
tp.derivedRefinedType(parent1, name, info)
737+
case _ =>
738+
tp.derivedRefinedType(parent = parent1)
739739
}
740740
case tp @ AppliedType(tycon, args) =>
741741
val tycon1 = tycon.safeDealias

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ trait Checking {
10921092
case tp @ AppliedType(tycon, args) =>
10931093
tp.derivedAppliedType(tycon, args.mapConserve(checkGoodBounds))
10941094
case tp: RefinedType =>
1095-
tp.derivedRefinedType(tp.parent, tp.refinedName, checkGoodBounds(tp.refinedInfo))
1095+
tp.derivedRefinedType(refinedInfo = checkGoodBounds(tp.refinedInfo))
10961096
case _ =>
10971097
tp
10981098
}

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ object Inferencing {
537537
}
538538
if tparams.isEmpty then tp else tp.derivedAppliedType(tycon, args1)
539539
case tp: AndOrType => tp.derivedAndOrType(captureWildcards(tp.tp1), captureWildcards(tp.tp2))
540-
case tp: RefinedType => tp.derivedRefinedType(captureWildcards(tp.parent), tp.refinedName, tp.refinedInfo)
540+
case tp: RefinedType => tp.derivedRefinedType(parent = captureWildcards(tp.parent))
541541
case tp: RecType => tp.derivedRecType(captureWildcards(tp.parent))
542542
case tp: LazyRef => captureWildcards(tp.ref)
543543
case tp: AnnotatedType => tp.derivedAnnotatedType(captureWildcards(tp.parent), tp.annot)

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
742742
def recur(handlers: SpecialHandlers): TreeWithErrors = handlers match
743743
case (cls, handler) :: rest =>
744744
def baseWithRefinements(tp: Type): Type = tp.dealias match
745-
case tp @ RefinedType(parent, rname, rinfo) =>
746-
tp.derivedRefinedType(baseWithRefinements(parent), rname, rinfo)
745+
case tp: RefinedType =>
746+
tp.derivedRefinedType(parent = baseWithRefinements(tp.parent))
747747
case _ =>
748748
tp.baseType(cls)
749749
val base = baseWithRefinements(formal)

0 commit comments

Comments
 (0)