Aladdin - Scala Bugtracking
[#846] project: specification priority: low category: bug
submitter assigned to status date submitted
Sean Martin fixed 2006-11-29 12:13:13.0
subject Silent coercion of null to compound type
code
package test;
trait Test {
  type Bar;
  trait FooImpl;
  trait Bob {
    def bar : Bar with FooImpl;
  }
  def ifn[A,B](a : A)(f : A => B) =
    if (a != null) f(a) else null;
  val bob : Bob = null;
  val bar = ifn(bob)(.bar);
  assert(bar == null);
}
what happened
Compiles fine.
what expected
[back to overview]
Changes of this bug report
Martin  edited on  2006-12-01 16:12:58.0
Why should it not compile?
Martin  edited on  2006-12-05 11:40:21.0
I think you want to define `ifn' with result type `B', otherwise the example compiles fine (ifn returns an Any). If you add the result type, it still compiled. That was a bug which I fixed now.