From 7cde70a7cfa4e9b0fa014be81bc3e47e027371e9 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 18 Jul 2019 15:35:45 +0200 Subject: [PATCH] Change definition of classSymbol for OrType --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++------ tests/run/memoTest.scala | 12 ++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 tests/run/memoTest.scala 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