Skip to content

Commit 874494a

Browse files
authored
Merge pull request scala#7142 from diesalbla/type_bounds_546
Add UpperBound and LowerBound methods to Type
2 parents 8a52aa1 + ed47913 commit 874494a

17 files changed

+75
-59
lines changed

src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
524524

525525
sClassMap.getOrElseUpdate(tparam,
526526
tparam.cloneSymbol(sClass, tparam.flags, tparam.name append tpnme.SPECIALIZED_SUFFIX)
527-
modifyInfo (info => TypeBounds(info.bounds.lo, AnyRefTpe))
527+
modifyInfo (info => TypeBounds(info.lowerBound, AnyRefTpe))
528528
).tpe
529529
}
530530

@@ -554,11 +554,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
554554
*/
555555
def produceTypeParameters(syms: List[Symbol], nowner: Symbol, env: TypeEnv) = {
556556
val cloned = for (s <- syms) yield if (!env.contains(s)) s.cloneSymbol(nowner) else env(s).typeSymbol
557-
// log("producing type params: " + cloned.map(t => (t, t.tpe.bounds.hi)))
557+
// log("producing type params: " + cloned.map(t => (t, t.tpe.upperBound)))
558558
foreach2(syms, cloned) { (orig, cln) =>
559559
cln.removeAnnotation(SpecializedClass)
560560
if (env.contains(orig))
561-
cln modifyInfo (info => TypeBounds(info.bounds.lo, AnyRefTpe))
561+
cln modifyInfo (info => TypeBounds(info.lowerBound, AnyRefTpe))
562562
}
563563
cloned map (_ substInfo (syms, cloned))
564564
}
@@ -625,7 +625,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
625625
val specializedInfoType: Type = {
626626
oldClassTParams = survivingParams(clazz.info.typeParams, env)
627627
newClassTParams = produceTypeParameters(oldClassTParams, sClass, env) map subst(env)
628-
// log("new tparams " + newClassTParams.zip(newClassTParams map {s => (s.tpe, s.tpe.bounds.hi)}) + ", in env: " + env)
628+
// log("new tparams " + newClassTParams.zip(newClassTParams map {s => (s.tpe, s.tpe.upperBound)}) + ", in env: " + env)
629629

630630
def applyContext(tpe: Type) =
631631
subst(env, tpe).instantiateTypeParams(oldClassTParams, newClassTParams map (_.tpe))
@@ -1277,7 +1277,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
12771277
* A conflicting type environment could still be satisfiable.
12781278
*/
12791279
def nonConflicting(env: TypeEnv) = env forall { case (tvar, tpe) =>
1280-
(subst(env, tvar.info.bounds.lo) <:< tpe) && (tpe <:< subst(env, tvar.info.bounds.hi))
1280+
(subst(env, tvar.info.lowerBound) <:< tpe) && (tpe <:< subst(env, tvar.info.upperBound))
12811281
}
12821282

12831283
/** The type environment is sound w.r.t. to all type bounds or only soft
@@ -1297,15 +1297,15 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
12971297
}
12981298

12991299
env forall { case (tvar, tpe) =>
1300-
matches(tvar.info.bounds.lo, tpe) && matches(tpe, tvar.info.bounds.hi) || {
1300+
matches(tvar.info.lowerBound, tpe) && matches(tpe, tvar.info.upperBound) || {
13011301
if (warnings)
13021302
reporter.warning(tvar.pos, s"Bounds prevent specialization of $tvar")
13031303

13041304
debuglog("specvars: " +
1305-
tvar.info.bounds.lo + ": " +
1306-
specializedTypeVars(tvar.info.bounds.lo) + " " +
1307-
subst(env, tvar.info.bounds.hi) + ": " +
1308-
specializedTypeVars(subst(env, tvar.info.bounds.hi))
1305+
tvar.info.lowerBound + ": " +
1306+
specializedTypeVars(tvar.info.lowerBound) + " " +
1307+
subst(env, tvar.info.upperBound) + ": " +
1308+
specializedTypeVars(subst(env, tvar.info.upperBound))
13091309
)
13101310
false
13111311
}
@@ -1329,8 +1329,8 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
13291329

13301330
env.foldLeft[Option[TypeEnv]](noconstraints) {
13311331
case (constraints, (tvar, tpe)) =>
1332-
val loconstraints = matches(tvar.info.bounds.lo, tpe)
1333-
val hiconstraints = matches(tpe, tvar.info.bounds.hi)
1332+
val loconstraints = matches(tvar.info.lowerBound, tpe)
1333+
val hiconstraints = matches(tpe, tvar.info.upperBound)
13341334
val allconstraints = for (c <- constraints; l <- loconstraints; h <- hiconstraints) yield c ++ l ++ h
13351335
allconstraints
13361336
}

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ abstract class UnCurry extends InfoTransform
274274
// Don't want bottom types getting any further than this (scala/bug#4024)
275275
if (tp.typeSymbol.isBottomClass) getClassTag(AnyTpe)
276276
else if (!tag.isEmpty) tag
277-
else if (tp.bounds.hi ne tp) getClassTag(tp.bounds.hi)
277+
else if (tp.upperBound ne tp) getClassTag(tp.upperBound)
278278
else localTyper.TyperErrorGen.MissingClassTagError(tree, tp)
279279
}
280280
def traversableClassTag(tpe: Type): Tree = {

src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ trait MatchTranslation {
169169
}
170170
def translate(): List[TreeMaker] = nextStep() merge (_.translate())
171171

172-
private def concreteType = tpe.bounds.hi
172+
private def concreteType = tpe.upperBound
173173
private def unbound = unbind(tree)
174174
private def tpe_s = if (pt <:< concreteType) "" + pt else s"$pt (binder: $tpe)"
175175
private def at_s = unbound match {

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ trait ContextErrors {
713713

714714
// SelectFromTypeTree
715715
def TypeSelectionFromVolatileTypeError(tree: Tree, qual: Tree) = {
716-
val hiBound = qual.tpe.bounds.hi
716+
val hiBound = qual.tpe.upperBound
717717
val addendum = if (hiBound =:= qual.tpe) "" else s" (with upper bound ${hiBound})"
718718
issueNormalTypeError(tree, s"illegal type selection from volatile type ${qual.tpe}${addendum}")
719719
setError(tree)

src/compiler/scala/tools/nsc/typechecker/Implicits.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ trait Implicits {
356356
sym.tpe match {
357357
case MethodType(params, restpe)
358358
if (params forall (_.tpe.isInstanceOf[BoundedWildcardType])) =>
359-
Some((sym.name, params map (_.tpe.bounds.lo), restpe))
359+
Some((sym.name, params map (_.tpe.lowerBound), restpe))
360360
case _ => None
361361
}
362362
case _ => None
@@ -482,8 +482,8 @@ trait Implicits {
482482
private def core(tp: Type): Type = tp.dealiasWiden match {
483483
case RefinedType(parents, defs) => intersectionType(parents map core, tp.typeSymbol.owner)
484484
case AnnotatedType(annots, tp) => core(tp)
485-
case ExistentialType(tparams, result) => core(result).subst(tparams, tparams map (t => core(t.info.bounds.hi)))
486-
case PolyType(tparams, result) => core(result).subst(tparams, tparams map (t => core(t.info.bounds.hi)))
485+
case ExistentialType(tparams, result) => core(result).subst(tparams, tparams map (t => core(t.info.upperBound)))
486+
case PolyType(tparams, result) => core(result).subst(tparams, tparams map (t => core(t.info.upperBound)))
487487
case TypeRef(pre, sym, args) =>
488488
val coreArgs = args.mapConserve(core)
489489
if (coreArgs eq args) tp
@@ -703,7 +703,7 @@ trait Implicits {
703703
else pt match {
704704
case tr @ TypeRef(pre, sym, args) =>
705705
if (sym.isAliasType) loop(tp, pt.dealias)
706-
else if (sym.isAbstractType) loop(tp, pt.bounds.lo)
706+
else if (sym.isAbstractType) loop(tp, pt.lowerBound)
707707
else {
708708
val ptFunctionArity = functionArity(pt)
709709
ptFunctionArity > 0 && hasLength(params, ptFunctionArity) && {
@@ -757,7 +757,7 @@ trait Implicits {
757757
case et: ExistentialType => et.underlying
758758
case tp => tp
759759
}
760-
val tp2Bounds = existentialUnderlying(tp2.dealiasWiden.bounds.hi)
760+
val tp2Bounds = existentialUnderlying(tp2.dealiasWiden.upperBound)
761761
tp2Bounds match {
762762
case TypeRef(_, sym2, args2) if sym2 ne SingletonClass =>
763763
val impossible = if ((sym1 eq sym2) && (args1 ne Nil)) !corresponds3(sym1.typeParams, args1, args2) {(tparam, arg1, arg2) =>
@@ -1285,7 +1285,7 @@ trait Implicits {
12851285
// SLS 2.12, section 7.2:
12861286

12871287
// - if `T` is an abstract type, the parts of its upper bound;
1288-
getParts(tp.bounds.hi)
1288+
getParts(tp.upperBound)
12891289

12901290
if (isScala213) {
12911291
// - if `T` is a parameterized type `S[T1,…,Tn]`, the union of the parts of `S` and `T1,…,Tn`
@@ -1474,7 +1474,7 @@ trait Implicits {
14741474
else findSubManifest(pre) :: suffix): _*)
14751475
} else if (sym.isExistentiallyBound && full) {
14761476
manifestFactoryCall("wildcardType", tp,
1477-
findManifest(tp.bounds.lo), findManifest(tp.bounds.hi))
1477+
findManifest(tp.lowerBound), findManifest(tp.upperBound))
14781478
}
14791479
// looking for a manifest of a type parameter that hasn't been inferred by now,
14801480
// can't do much, but let's not fail
@@ -1555,7 +1555,7 @@ trait Implicits {
15551555
private def materializeImplicit(pt: Type): SearchResult =
15561556
pt match {
15571557
case TypeRef(_, sym, _) if sym.isAbstractType =>
1558-
materializeImplicit(pt.dealias.bounds.lo) // #3977: use pt.dealias, not pt (if pt is a type alias, pt.bounds.lo == pt)
1558+
materializeImplicit(pt.dealias.lowerBound) // #3977: use pt.dealias, not pt (if pt is a type alias, pt.lowerBound == pt)
15591559
case pt @ TypeRef(pre, sym, arg :: Nil) =>
15601560
sym match {
15611561
case sym if ManifestSymbols(sym) => manifestOfType(arg, sym)

src/compiler/scala/tools/nsc/typechecker/Infer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ trait Infer extends Checkable {
545545
// explicitly anywhere amongst the formal, argument, result, or expected type.
546546
// ...or lower bound of a type param, since they're asking for it.
547547
def canWarnAboutAny = {
548-
val loBounds = tparams map (_.info.bounds.lo)
548+
val loBounds = tparams map (_.info.lowerBound)
549549
def containsAny(t: Type) = (t contains AnyClass) || (t contains AnyValClass) || (t contains ObjectClass)
550550
val hasAny = pt :: restpe :: formals ::: argtpes ::: loBounds exists (_.dealiasWidenChain exists containsAny)
551551
!hasAny

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ abstract class RefChecks extends Transform {
517517
kindErrors.toList.mkString("\n", ", ", ""))
518518
}
519519
}
520-
else if (low.isAbstractType && lowType.isVolatile && !highInfo.bounds.hi.isVolatile)
520+
else if (low.isAbstractType && lowType.isVolatile && !highInfo.upperBound.isVolatile)
521521
overrideError("is a volatile type; cannot override a type with non-volatile upper bound")
522522
}
523523
def checkOverrideTerm(): Unit = {
@@ -977,7 +977,7 @@ abstract class RefChecks extends Transform {
977977
}
978978
def underlyingClass(tp: Type): Symbol = {
979979
val sym = tp.widen.typeSymbol
980-
if (sym.isAbstractType) underlyingClass(sym.info.bounds.hi)
980+
if (sym.isAbstractType) underlyingClass(sym.info.upperBound)
981981
else sym
982982
}
983983
val actual = underlyingClass(other.tpe)
@@ -1331,7 +1331,7 @@ abstract class RefChecks extends Transform {
13311331
// types of the value parameters
13321332
mapParamss(member)(p => checkAccessibilityOfType(p.tpe))
13331333
// upper bounds of type parameters
1334-
member.typeParams.map(_.info.bounds.hi.widen) foreach checkAccessibilityOfType
1334+
member.typeParams.map(_.info.upperBound.widen) foreach checkAccessibilityOfType
13351335
}
13361336

13371337
/** Check that a deprecated val or def does not override a

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
516516
def expectsStable = (
517517
pt.isStable
518518
|| mode.inQualMode && !tree.symbol.isConstant
519-
|| !(tree.tpe <:< pt) && (ptSym.isAbstractType && pt.bounds.lo.isStable || ptSym.isRefinementClass)
519+
|| !(tree.tpe <:< pt) && (ptSym.isAbstractType && pt.lowerBound.isStable || ptSym.isRefinementClass)
520520
)
521521

522522
( isNarrowable(tree.tpe)
@@ -2185,7 +2185,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
21852185
log(s"""checking $tp0 in refinement$parentString at ${meth.owner.owner.fullLocationString}""")
21862186
( (!sym.hasTransOwner(meth.owner) && failStruct(paramPos, "an abstract type defined outside that refinement", what))
21872187
|| (!sym.hasTransOwner(meth) && failStruct(paramPos, "a type member of that refinement", what))
2188-
|| checkAbstract(sym.info.bounds.hi, "Type bound")
2188+
|| checkAbstract(sym.info.upperBound, "Type bound")
21892189
)
21902190
}
21912191
tp0.dealiasWidenChain forall (t => check(t.typeSymbol))
@@ -3217,7 +3217,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
32173217
* in an argument closure overlaps with an uninstantiated formal?
32183218
*/
32193219
def needsInstantiation(tparams: List[Symbol], formals: List[Type], args: List[Tree]) = {
3220-
def isLowerBounded(tparam: Symbol) = !tparam.info.bounds.lo.typeSymbol.isBottomClass
3220+
def isLowerBounded(tparam: Symbol) = !tparam.info.lowerBound.typeSymbol.isBottomClass
32213221

32223222
exists2(formals, args) {
32233223
case (formal, Function(vparams, _)) =>
@@ -3603,7 +3603,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
36033603
val args1 = map2(args, formals)(typedArgToPoly)
36043604
if (args1 exists { _.isErrorTyped }) duplErrTree
36053605
else {
3606-
debuglog("infer method inst " + fun + ", tparams = " + tparams + ", args = " + args1.map(_.tpe) + ", pt = " + pt + ", lobounds = " + tparams.map(_.tpe.bounds.lo) + ", parambounds = " + tparams.map(_.info)) //debug
3606+
debuglog("infer method inst " + fun + ", tparams = " + tparams + ", args = " + args1.map(_.tpe) + ", pt = " + pt + ", lobounds = " + tparams.map(_.tpe.lowerBound) + ", parambounds = " + tparams.map(_.info)) //debug
36073607
// define the undetparams which have been fixed by this param list, replace the corresponding symbols in "fun"
36083608
// returns those undetparams which have not been instantiated.
36093609
val undetparams = inferMethodInstance(fun, tparams, args1, pt)

src/reflect/scala/reflect/internal/Definitions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ trait Definitions extends api.StandardDefinitions {
851851
case _: SingletonType => true
852852
case NoPrefix => true
853853
case TypeRef(_, NothingClass | SingletonClass, _) => true
854-
case TypeRef(_, sym, _) if sym.isAbstractType => tp.bounds.hi.typeSymbol isSubClass SingletonClass
854+
case TypeRef(_, sym, _) if sym.isAbstractType => tp.upperBound.typeSymbol isSubClass SingletonClass
855855
case TypeRef(pre, sym, _) if sym.isModuleClass => isStable(pre)
856856
case TypeRef(_, _, _) => val normalize = tp.normalize; (normalize ne tp) && isStable(normalize)
857857
case TypeVar(origin, _) => isStable(origin)
@@ -866,7 +866,7 @@ trait Definitions extends api.StandardDefinitions {
866866
// indirectly upper-bounded by itself. See #2918
867867
def isVolatileAbstractType: Boolean = {
868868
def sym = tp.typeSymbol
869-
def volatileUpperBound = isVolatile(tp.bounds.hi)
869+
def volatileUpperBound = isVolatile(tp.upperBound)
870870
def safeIsVolatile = (
871871
if (volatileRecursions < TypeConstants.LogVolatileThreshold)
872872
volatileUpperBound

src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ trait ExistentialsAndSkolems {
4949
*/
5050
private def existentialBoundsExcludingHidden(hidden: List[Symbol]): Map[Symbol, Type] = {
5151
def safeBound(t: Type): Type =
52-
if (hidden contains t.typeSymbol) safeBound(t.typeSymbol.existentialBound.bounds.hi) else t
52+
if (hidden contains t.typeSymbol) safeBound(t.typeSymbol.existentialBound.upperBound) else t
5353

54-
def hiBound(s: Symbol): Type = safeBound(s.existentialBound.bounds.hi).resultType match {
54+
def hiBound(s: Symbol): Type = safeBound(s.existentialBound.upperBound).resultType match {
5555
case tp @ RefinedType(parents, decls) =>
5656
val parents1 = parents mapConserve safeBound
5757
if (parents eq parents1) tp

src/reflect/scala/reflect/internal/Symbols.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
19091909
*/
19101910
final def isLess(that: Symbol): Boolean = {
19111911
def baseTypeSeqLength(sym: Symbol) =
1912-
if (sym.isAbstractType) 1 + sym.info.bounds.hi.baseTypeSeq.length
1912+
if (sym.isAbstractType) 1 + sym.info.upperBound.baseTypeSeq.length
19131913
else sym.info.baseTypeSeq.length
19141914
if (this.isType)
19151915
(that.isType &&
@@ -2789,12 +2789,12 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
27892789
private def compose(ss: String*) = ss filter (_ != "") mkString " "
27902790

27912791
def isSingletonExistential =
2792-
nme.isSingletonName(name) && (info.bounds.hi.typeSymbol isSubClass SingletonClass)
2792+
nme.isSingletonName(name) && (info.upperBound.typeSymbol isSubClass SingletonClass)
27932793

27942794
/** String representation of existentially bound variable */
27952795
def existentialToString =
27962796
if (isSingletonExistential && !settings.debug.value)
2797-
"val " + tpnme.dropSingletonName(name) + ": " + dropSingletonType(info.bounds.hi)
2797+
"val " + tpnme.dropSingletonName(name) + ": " + dropSingletonType(info.upperBound)
27982798
else defString
27992799
}
28002800
implicit val SymbolTag = ClassTag[Symbol](classOf[Symbol])

0 commit comments

Comments
 (0)