diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 0d3901e9c252..eb22e1bb682d 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -431,12 +431,8 @@ object Types { if (lsym isSubClass rsym) lsym else if (rsym isSubClass lsym) rsym else NoSymbol - case OrType(l, r) => // TODO does not conform to spec - val lsym = l.classSymbol - val rsym = r.classSymbol - if (lsym isSubClass rsym) rsym - else if (rsym isSubClass lsym) lsym - else NoSymbol + case tp: OrType => + tp.join.classSymbol case _ => NoSymbol } diff --git a/tests/run/memoTest.scala b/tests/run/memoTest.scala new file mode 100644 index 000000000000..460991eeaa59 --- /dev/null +++ b/tests/run/memoTest.scala @@ -0,0 +1,12 @@ +object Test extends App { + + var opCache: Int | Null = null + + def foo(x: Int) = { + if (opCache == null) opCache = x + opCache.asInstanceOf[Int] + 1 + } + + assert(foo(1) + foo(2) == 4) + +} \ No newline at end of file