Skip to content

Fix #11464: avoid expanding local paramRef in HKTypeLambda #11465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ object TypeOps:
def avoid(tp: Type, symsToAvoid: => List[Symbol])(using Context): Type = {
val widenMap = new ApproximatingTypeMap {
@threadUnsafe lazy val forbidden = symsToAvoid.toSet
@threadUnsafe lazy val localParamRefs = util.HashSet[Type]()
def toAvoid(sym: Symbol) = !sym.isStatic && forbidden.contains(sym)
def partsToAvoid = new NamedPartsAccumulator(tp => toAvoid(tp.symbol))

Expand Down Expand Up @@ -429,17 +430,25 @@ object TypeOps:
case _ =>
emptyRange // should happen only in error cases
}
case tp: ThisType if toAvoid(tp.cls) =>
range(defn.NothingType, apply(classBound(tp.cls.classInfo)))
case tp: ThisType =>
// ThisType is only used inside a class.
// Therefore, either they don't appear in the type to be avoided, or
// it must be a class that encloses the block whose type is to be avoided.
tp
Copy link
Contributor Author

@liufengyun liufengyun Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case tp: SkolemType if partsToAvoid(Nil, tp.info).nonEmpty =>
range(defn.NothingType, apply(tp.info))
case tp: TypeVar if mapCtx.typerState.constraint.contains(tp) =>
val lo = TypeComparer.instanceType(
tp.origin, fromBelow = variance > 0 || variance == 0 && tp.hasLowerBound)(using mapCtx)
val lo1 = apply(lo)
if (lo1 ne lo) lo1 else tp
case tp: LazyRef if isExpandingBounds =>
emptyRange
case tp: LazyRef =>
if localParamRefs.contains(tp.ref) then tp
else if isExpandingBounds then emptyRange
else mapOver(tp)
case tl: HKTypeLambda =>
localParamRefs ++= tl.paramRefs
mapOver(tl)
case _ =>
mapOver(tp)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2924,7 +2924,7 @@ object Types {
tp match {
case tp: TypeRef => apply(x, tp.prefix)
case tp: RecThis => RecType.this eq tp.binder
case tp: LazyRef => true // To be safe, assume a reference exists
case tp: LazyRef => this(x, tp.ref)
case _ => foldOver(x, tp)
}
}
Expand Down
1 change: 0 additions & 1 deletion compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ i9793.scala

# lazy_implicit symbol has different position after pickling
i8182.scala

16 changes: 16 additions & 0 deletions tests/pos/i11464.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait Txn[T <: Txn[T]]

trait Adjunct

trait Type0
trait Type[A1, Repr[~ <: Txn[~]] <: Expr[~, A1]] extends Type0

object Expr {
def test(peer: Type0): Adjunct = {
new AdjunctImpl(peer.asInstanceOf[Type[Any, ({ type R[~ <: Txn[~]] <: Expr[~, Any] }) # R]])
}
}

trait Expr[T <: Txn[T], +A]

class AdjunctImpl[A, E[~ <: Txn[~]] <: Expr[~, A]](tpe: Type[A, E]) extends Adjunct