Skip to content

Out of memory while producing Type Mismatch error message #5327

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

Closed
panacekcz opened this issue Oct 25, 2018 · 1 comment · Fixed by #9141
Closed

Out of memory while producing Type Mismatch error message #5327

panacekcz opened this issue Oct 25, 2018 · 1 comment · Fixed by #9141
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@panacekcz
Copy link
Contributor

This code (based on i3965.scala; notice the added intersection) should not compile. However, the compiler seems to get in some sort of infinite recursion, runs for a few minutes and then fails with Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded.

trait T
trait SortedSetOps[CC[X], C]
class TreeSet[A] extends SortedSetOps[TreeSet, TreeSet[A]]

class Test {
  def optionSequence1[CC[X] <: (SortedSetOps[CC, CC[X]] & T) , A](xs: CC[A]): Unit = ()
  def test(xs2: TreeSet[String]) = {
    optionSequence1(xs2)
  }
}

(If & T is removed, or with T is added to TreeSet, it compiles fine.)

This variant also fails, but it possibly could compile by inferring CC to be [X] => (TreeSet[X] & T):

trait T
trait SortedSetOps[CC[X], C]
class TreeSet[A] extends SortedSetOps[[X] => (TreeSet[X] & T), TreeSet[A] & T]

class Test {
  def optionSequence1[CC[X] <: (SortedSetOps[CC, CC[X]] & T) , A](xs: CC[A]): Unit = ()
  def test(xs2: TreeSet[String] & T) = {
    optionSequence1(xs2)
  }
}

When the type parameters are specified explicitly, optionSequence1[[X] => (TreeSet[X] & T), String](xs2), it compiles fine.

@panacekcz
Copy link
Contributor Author

Actually, in the first case, the intersection is not important. The problem is that there is a type mismatch and the compiler seems to get stuck trying to produce the error message.
Simplified test:

trait SortedSetOps[CC[X], C]
class TreeSet[A] extends SortedSetOps[TreeSet, TreeSet[A]]

class Test {
  def optionSequence1[CC[X] <: SortedSetOps[CC, CC[X]] , A](xs: CC[A]): Unit = ()

  def test(xs2: Int) = {
    optionSequence1(xs2)
  }
}

If I remove the applications of the reported type map in ErrorReporting.Errors.typeMismatchMsg, then I get this type mismatch error:

-- [E007] Type Mismatch Error: i3965Error.scala:8:20 ---------------
8 |    optionSequence1(xs2)
  |                    ^^^
  |found:    Int(xs2)
  |required: CC[A]
  |
  |where:    A  is a type variable
  |          CC is a type variable with constraint <: [X] => SortedSetOps[LazyRef(CC), LazyRef(CC[X])]
one error found

That means reported needs some kind of protection against infinite recursion.

@panacekcz panacekcz changed the title Out of memory with inferred type lambda and intersection Out of memory while producing Type Mismatch error message Nov 17, 2018
@allanrenucci allanrenucci added itype:bug area:reporting Error reporting including formatting, implicit suggestions, etc labels Nov 17, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 9, 2020
@nicolasstucki nicolasstucki linked a pull request Jun 9, 2020 that will close this issue
anatoliykmetyuk added a commit that referenced this issue Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants