Aladdin - Scala Bugtracking
[#344] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Vincent Philippe fixed 2004-06-11 12:51:55.0
subject nested ifs type inference
code
object Bug {
  class A;
  case class A1 extends A;
  case class A2 extends A;
  def f: A =
    if (true)
      A1()
    else {
      val a = if (true) A1() else A2();
      a
    };
}
what happened
Compiler crash during ExplicitOuterClassesPhase.
what expected The program should compile normally. It 's what happen in the following cases :
  • We give an explicit type to the value a.
  • We skip the outermost if.
  • We use normal classes instead of case classes.
[back to overview]
Changes of this bug report
Philippe  edited on  2004-06-11 17:54:14.0

Here is a version without case classes.

class A; trait I; class A1 extends A with I; class A2 extends A with I; object Bug { if (true) new A1() else { val a = if (true) new A1() else new A2(); a }; }

The problem comes from the inferred type for "val a" which is "A with I". This is a compound type. Currently compound types have a symbol whose owner is often uncorrect. That's probably the cause of the crash.

Note that the fact that the inferred type is "A with I" instead of just A seems to be a bug.

Here is an example where the inferred type is a legitimate compound type.

trait A; trait B; class AB1 extends A with B; class AB2 extends A with B; object Bug { if (true) new AB1() else { val a = if (true) new AB1() else new AB2(); a }; }
Philippe  edited on  2004-06-11 18:01:57.0
The remark about the uncorrect compound type is incorrect. The compound types are legitimate in all examples.
Lex  edited on  2006-03-28 14:16:01.0