Skip to content

Guard against stackoverflows when instantiating HK-Lambdas #14851

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 1 commit into from
Apr 5, 2022
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
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,15 @@ class TypeApplications(val self: Type) extends AnyVal {
}
}
if ((dealiased eq stripped) || followAlias)
try {
try
val instantiated = dealiased.instantiate(args)
if (followAlias) instantiated.normalized else instantiated
}
catch { case ex: IndexOutOfBoundsException => AppliedType(self, args) }
catch
case ex: IndexOutOfBoundsException =>
AppliedType(self, args)
case ex: Throwable =>
handleRecursive("try to instantiate", i"$dealiased[$args%, %]", ex)

else AppliedType(self, args)
}
else dealiased.resType match {
Expand Down
30 changes: 30 additions & 0 deletions tests/neg/i2887b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- Error: tests/neg/i2887b.scala:11:7 ----------------------------------------------------------------------------------
11 | baz(new A { type S[X[_] <: [_] =>> Any, Y[_]] = [Z] =>> X[Z][Y[Z]]; type I[X] = X })(1) // error
| ^
| Recursion limit exceeded.
| Maybe there is an illegal cyclic reference?
| If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
| A recurring operation is (inner to outer):
|
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| ...
|
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
| try to instantiate Z[Z]
10 changes: 5 additions & 5 deletions tests/neg/i2887b.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
trait A { type S[X[_] <: [_] => Any, Y[_]] <: [_] => Any; type I[_] } // error // error
trait B { type S[X[_],Y[_]]; type I[_] <: [_] => Any } // error
trait A { type S[X[_] <: [_] =>> Any, Y[_]] <: [_] =>> Any; type I[_] }
trait B { type S[X[_],Y[_]]; type I[_] <: [_] =>> Any }
trait C { type M <: B }
trait D { type M >: A }

object Test {
def test(x: C with D): Unit = {
def foo(a: A, b: B)(z: a.S[b.I,a.I][b.S[a.I,a.I]]) = z // error
def foo(a: A, b: B)(z: a.S[b.I,a.I][b.S[a.I,a.I]]) = z
def bar(a: A, y: x.M) = foo(a,y)
def baz(a: A) = bar(a, a)
baz(new A { type S[X[_] <: [_] => Any, Y[_]] = [Z] => X[Z][Y[Z]]; type I[X] = X })(1) // error // error
baz(new A { type S[X[_] <: [_] =>> Any, Y[_]] = [Z] =>> X[Z][Y[Z]]; type I[X] = X })(1) // error
}
}
}