Skip to content

Fix #3882: Take LazyRefs into account for monitored subtype checking #3885

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 2 commits into from
Jan 22, 2018
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
18 changes: 17 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,23 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2)))
}
val p = (tp1, tp2)
// Eliminate LazyRefs before checking whether we have seen a type before
val normalize = new TypeMap {
val DerefLimit = 10
var derefCount = 0
def apply(t: Type) = t match {
case t: LazyRef =>
// Dereference a lazyref to detect underlying matching types, but
// be careful not to get into an infinite recursion. If recursion count
// exceeds `DerefLimit`, approximate with `NoType` instead.
derefCount += 1
if (derefCount >= DerefLimit) NoType
else try mapOver(t.ref) finally derefCount -= 1
case _ =>
mapOver(t)
}
}
val p = (normalize(tp1), normalize(tp2))
!pendingSubTypes(p) && {
try {
pendingSubTypes += p
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class CompilationTests extends ParallelTesting {
compileFile("../tests/neg-custom-args/pureStatement.scala", defaultOptions.and("-Xfatal-warnings")) +
compileFile("../tests/neg-custom-args/i3589-a.scala", defaultOptions.and("-Xfatal-warnings")) +
compileFile("../tests/neg-custom-args/i2333.scala", defaultOptions.and("-Xfatal-warnings")) +
compileFile("../tests/neg-custom-args/i3882.scala", allowDeepSubtypes) +
compileFile("../tests/neg-custom-args/phantom-overload.scala", allowDoubleBindings) +
compileFile("../tests/neg-custom-args/phantom-overload-2.scala", allowDoubleBindings) +
compileFile("../tests/neg-custom-args/structural.scala", defaultOptions.and("-Xfatal-warnings"))
Expand Down
5 changes: 5 additions & 0 deletions tests/neg-custom-args/i3882.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait Ring[A <: Ring[A]]

object Test {
def crash[T <: Ring[_ <: T]]: Ring[T] = ??? // error: Type argument T does not conform to upper bound Ring[LazyRef(T)]
}