Skip to content

Commit

Permalink
Add default arguments to derived refined type (#18435)
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky authored Oct 1, 2023
2 parents f859640 + ab9f882 commit 2be96cf
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class CheckCaptures extends Recheck, SymTransformer:
case _ =>
val t1 = t match
case t @ defn.RefinedFunctionOf(rinfo: MethodType) =>
t.derivedRefinedType(t.parent, t.refinedName, this(rinfo))
t.derivedRefinedType(refinedInfo = this(rinfo))
case _ =>
mapOver(t)
if variance > 0 then t1
Expand Down Expand Up @@ -948,7 +948,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 @@ -689,7 +689,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 @@ -1824,7 +1824,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
12 changes: 7 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,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 @@ -3226,7 +3226,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 @@ -4130,7 +4132,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 Expand Up @@ -5631,8 +5633,8 @@ object Types {
else hi
case (arg, _) => arg
tp.derivedAppliedType(tycon, args1)
case tp @ RefinedType(parent, name, info) =>
tp.derivedRefinedType(approxWildcardArgs(parent), name, info)
case tp: RefinedType =>
tp.derivedRefinedType(approxWildcardArgs(tp.parent))
case _ =>
tp
approxWildcardArgs(tp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,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 @@ -1092,7 +1092,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 @@ -742,8 +742,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 2be96cf

Please sign in to comment.