Aladdin - Scala Bugtracking
[#362] project: compiler priority: low category: bug
submitter assigned to status date submitted
Michel Martin fixed 2004-09-21 11:04:31.0
subject Wrong code for sub-classes of inner classes defined inside functions
code
class O {
  class I { }
}

object Main {
  def f(x: O) = {
    class C extends x.I;
  }
}
what happened
It compiled.
what expected An error. Although I cannot really say what the problem is, the code after AddConstructors is definitely wrong, type-wise. The class C then looks like this (simplified):
  class C$0[outer$0$Main$Main <: Main]() extends I[x$0.type]() with ScalaObject() {
    def <init>(outer$0$Main: outer$0$Main$Main, x$0: O): Unit = {
      {
        C$0.super.<init>(x$0);
        ()
      };
      ()
    }
  };
The extends I[x$0.type]() is clearly wrong, as x$0 is not in scope at this point.

The problem here is that LambdaLift, when it extracts C from f, adds a value parameter to C to represent x. This parameter is then directly used in the extends clause, as the prefix for I. This is something that cannot be done by hand, and maybe the compiler shouldn't do it either. But I don't really know. Any ideas?

[back to overview]
Changes of this bug report
Martin  edited on  2004-11-19 19:39:59.0
I would expect the program to compile correctly! The problem is that after lambda lift, the program is no longer well typed. This is inherent in the specification of lambda lift. Two possible solutions: (1) somehow ignore that the program is illtyped. (2) do erasure and run-time types before lambda lift. Others solutions?
Martin  edited on  2006-03-30 18:43:36.0
Problem does not apply in version 2, because lambdalift is now done after erasure