Skip to content

Commit 68ea8a4

Browse files
committed
Drop withoutArgs
1 parent 762f16b commit 68ea8a4

File tree

6 files changed

+16
-43
lines changed

6 files changed

+16
-43
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
380380
/** new C(args), calling given constructor `constr` of C */
381381
def New(tp: Type, constr: TermSymbol, args: List[Tree])(implicit ctx: Context): Apply = {
382382
val targs = tp.argTypes
383-
val tycon = tp.withoutArgs(targs)
383+
val tycon = tp.typeConstructor
384384
New(tycon)
385385
.select(TermRef.withSig(tycon, constr))
386386
.appliedToTypes(targs)

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
296296
(tycon, targs)
297297
case TypedSplice(AppliedTypeTree(tycon, targs)) =>
298298
(TypedSplice(tycon), targs map (TypedSplice(_)))
299-
case TypedSplice(tpt1: Tree) =>
299+
case TypedSplice(tpt1: tpd.Tree) =>
300+
val tycon = tpt1.tpe.typeConstructor
300301
val argTypes = tpt1.tpe.argTypesLo
301-
val tycon = tpt1.tpe.withoutArgs(argTypes)
302302
def wrap(tpe: Type) = TypeTree(tpe) withPos tpt.pos
303303
(wrap(tycon), argTypes map wrap)
304304
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ object Annotations {
103103

104104
private def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = {
105105
val targs = atp.argTypes
106-
tpd.applyOverloaded(New(atp withoutArgs targs), nme.CONSTRUCTOR, args, targs, atp, isAnnotConstructor = true)
106+
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp, isAnnotConstructor = true)
107107
}
108108

109109
def applyResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation = {

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

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ class TypeApplications(val self: Type) extends AnyVal {
173173
*/
174174
final def typeParams(implicit ctx: Context): List[TypeParamInfo] = /*>|>*/ track("typeParams") /*<|<*/ {
175175
self match {
176-
case self: ClassInfo =>
177-
self.cls.typeParams
178-
case self: HKTypeLambda =>
179-
self.typeParams
180176
case self: TypeRef =>
181177
val tsym = self.symbol
182178
if (tsym.isClass) tsym.typeParams
183179
else if (!tsym.isCompleting) tsym.info.typeParams
184180
else Nil
181+
case self: ClassInfo =>
182+
self.cls.typeParams
183+
case self: HKTypeLambda =>
184+
self.typeParams
185185
case self: RefinedType =>
186-
self.parent.typeParams.filterNot(_.paramName == self.refinedName) // @!!!
186+
self.parent.typeParams
187187
case self: RecType =>
188188
self.parent.typeParams
189189
case _: SingletonType =>
@@ -432,12 +432,6 @@ class TypeApplications(val self: Type) extends AnyVal {
432432
case _ => TypeAlias(self)
433433
}
434434

435-
/** The type arguments of this type's base type instance wrt. `base`.
436-
* Wildcard types in arguments are returned as TypeBounds instances.
437-
*/
438-
final def baseArgInfos(base: Symbol)(implicit ctx: Context): List[Type] = // @!!! drop
439-
self.baseType(base).argInfos
440-
441435
/** Translate a type of the form From[T] to To[T], keep other types as they are.
442436
* `from` and `to` must be static classes, both with one type parameter, and the same variance.
443437
* Do the same for by name types => From[T] and => To[T]
@@ -446,9 +440,7 @@ class TypeApplications(val self: Type) extends AnyVal {
446440
case self @ ExprType(tp) =>
447441
self.derivedExprType(tp.translateParameterized(from, to))
448442
case _ =>
449-
if (self.derivesFrom(from))
450-
if (ctx.erasedTypes) to.typeRef // @!!! can be dropped; appliedTo does the right thing anyway
451-
else to.typeRef.appliedTo(self.baseType(from).argInfos)
443+
if (self.derivesFrom(from)) to.typeRef.appliedTo(self.baseType(from).argInfos)
452444
else self
453445
}
454446

@@ -480,21 +472,6 @@ class TypeApplications(val self: Type) extends AnyVal {
480472
/** Argument types where existential types in arguments are approximated by their upper bound */
481473
def argTypesHi(implicit ctx: Context) = argInfos.mapConserve(_.hiBound)
482474

483-
/** The core type without any type arguments.
484-
* @param `typeArgs` must be the type arguments of this type.
485-
*/
486-
final def withoutArgs(typeArgs: List[Type]): Type = self match { // @!!! replace with typeConstructor?
487-
case AppliedType(tycon, args) => tycon
488-
case _ =>
489-
typeArgs match {
490-
case _ :: typeArgs1 =>
491-
val RefinedType(tycon, _, _) = self // @!!!
492-
tycon.withoutArgs(typeArgs1)
493-
case nil =>
494-
self
495-
}
496-
}
497-
498475
/** If this is the image of a type argument; recover the type argument,
499476
* otherwise NoType.
500477
*/
@@ -514,6 +491,6 @@ class TypeApplications(val self: Type) extends AnyVal {
514491
def elemType(implicit ctx: Context): Type = self match {
515492
case defn.ArrayOf(elemtp) => elemtp
516493
case JavaArrayType(elemtp) => elemtp
517-
case _ => baseArgInfos(defn.SeqClass).headOption.getOrElse(NoType)
494+
case _ => self.baseType(defn.SeqClass).argInfos.headOption.getOrElse(NoType)
518495
}
519496
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ object Scala2Unpickler {
6262
case tp: MethodType =>
6363
val lastArg = tp.paramInfos.last
6464
assert(lastArg isRef defn.ArrayClass)
65-
val elemtp0 :: Nil = lastArg.baseArgInfos(defn.ArrayClass)
65+
val elemtp0 :: Nil = lastArg.baseType(defn.ArrayClass).argInfos
6666
val elemtp = elemtp0 match {
6767
case AndType(t1, t2) if t1.typeSymbol.isAbstractType && (t2 isRef defn.ObjectClass) =>
6868
t1 // drop intersection with Object for abstract types in varargs. UnCurry can handle them.
@@ -927,7 +927,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
927927
// println(atp)
928928
val targs = atp.argTypes
929929

930-
tpd.applyOverloaded(tpd.New(atp withoutArgs targs), nme.CONSTRUCTOR, args, targs, atp)
930+
tpd.applyOverloaded(tpd.New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
931931
}
932932

933933
/** Read an annotation and as a side effect store it into

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,19 +536,15 @@ object RefChecks {
536536
def subclassMsg(c1: Symbol, c2: Symbol) =
537537
s": ${c1.showLocated} is a subclass of ${c2.showLocated}, but method parameter types must match exactly."
538538
val addendum =
539-
if (abstractSym == concreteSym) {
540-
val paArgs = pa.argInfos
541-
val pcArgs = pc.argInfos
542-
val paConstr = pa.withoutArgs(paArgs)
543-
val pcConstr = pc.withoutArgs(pcArgs)
544-
(paConstr, pcConstr) match {
539+
if (abstractSym == concreteSym)
540+
(pa.typeConstructor, pc.typeConstructor) match {
545541
case (TypeRef(pre1, _), TypeRef(pre2, _)) =>
546542
if (pre1 =:= pre2) ": their type parameters differ"
547543
else ": their prefixes (i.e. enclosing instances) differ"
548544
case _ =>
549545
""
550546
}
551-
} else if (abstractSym isSubClass concreteSym)
547+
else if (abstractSym isSubClass concreteSym)
552548
subclassMsg(abstractSym, concreteSym)
553549
else if (concreteSym isSubClass abstractSym)
554550
subclassMsg(concreteSym, abstractSym)

0 commit comments

Comments
 (0)