Skip to content

Commit

Permalink
Preserve kind of relativeInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Jan 5, 2021
1 parent 69b04d1 commit cd13abc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -2438,7 +2438,7 @@ trait Types


// interpret symbol's info in terms of the type's prefix and type args
protected def relativeInfo: Type = appliedType(sym.info.asSeenFrom(pre, sym.owner), argsOrDummies)
protected def relativeInfo: Type = appliedType(sym.info.asSeenFrom(pre, sym.owner), args)

// @M: propagate actual type params (args) to `tp`, by replacing
// formal type parameters with actual ones. If tp is higher kinded,
Expand Down
15 changes: 8 additions & 7 deletions src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
Expand Up @@ -345,17 +345,18 @@ private[internal] trait TypeMaps {
val tp1 = mapOver(tp)
if (variance.isInvariant) tp1
else tp1 match {
case TypeRef(_, sym, typeArgs) if tparams.contains(sym) && occurCount(sym) == 1 =>
case TypeRef(pre, sym, args) if tparams.contains(sym) && occurCount(sym) == 1 =>
val repl = if (variance.isPositive) dropSingletonType(tp1.upperBound) else tp1.lowerBound
def msg = {
val word = if (variance.isPositive) "upper" else "lower"
s"Widened lone occurrence of $tp1 inside existential to $word bound"
}

val widened = if (variance.isPositive) dropSingletonType(tp1.upperBound) else tp1.lowerBound
if (widened.typeSymbol.isBottomClass || anyContains.collect(widened)) tp1
else debuglogResult(msg)(appliedType(genPolyType(sym.typeParams, widened), typeArgs))
case other =>
other
if (!repl.typeSymbol.isBottomClass && ! anyContains.collect(repl))
debuglogResult(msg)(repl)
else
tp1
case _ =>
tp1
}
}
override def mapOver(tp: Type): Type = tp match {
Expand Down
4 changes: 2 additions & 2 deletions test/files/run/repl-kind.check
Expand Up @@ -14,8 +14,8 @@ Either's kind is F[+A1,+A2]
This is a type constructor: a 1st-order-kinded type.

scala> :k -v scala.collection.SortedMapOps
scala.collection.SortedMapOps's kind is X[K,+V,+CC[X,Y] <: scala.collection.Map[X,Y] with scala.collection.SortedMapOps[X, Y, CC, _],+C <: scala.collection.SortedMapOps[K,V,CC,C]]
* -> * -(+)-> (* -> * -> *(scala.collection.Map[X,Y] with scala.collection.SortedMapOps[X, Y, CC, _])) -(+)-> *(scala.collection.SortedMapOps[K,V,CC,C]) -(+)-> *
scala.collection.SortedMapOps's kind is X[K,+V,+CC[X,Y] <: [X, Y]scala.collection.Map[X,Y] with scala.collection.SortedMapOps[X, Y, CC, _],+C <: scala.collection.SortedMapOps[K,V,CC,C]]
* -> * -(+)-> (* -> * -> *([X, Y]scala.collection.Map[X,Y] with scala.collection.SortedMapOps[X, Y, CC, _])) -(+)-> *(scala.collection.SortedMapOps[K,V,CC,C]) -(+)-> *
This is a type constructor that takes type constructor(s): a higher-kinded type.

scala> :kind -v Tuple2
Expand Down

0 comments on commit cd13abc

Please sign in to comment.