From 0eff6cd49d32c20d5648b57a01b5e80339a1cca7 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 19 Feb 2013 12:57:21 -0800 Subject: Fix and optimization in overriding logic. Given: trait Foo { def f: Int = 5 } trait Bar extends Foo { def f: Int } I noticed allOverriddenSymbols for the abstract f defined in Bar was returning the method from Foo, even though an abstract method cannot override a concrete one. There were other bits of code which accidentally depended on this outcome. Now allOverriddenSymbols for Bar is empty. The optimization is that whether or not a symbol overrides any other symbols is known at creation time and does not change. We now spend a lot less time looking for overridden symbols in base classes by storing that value, "isOverridingSymbol". --- test/files/run/all-overridden.check | 1 + test/files/run/all-overridden.scala | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/files/run/all-overridden.check create mode 100644 test/files/run/all-overridden.scala (limited to 'test/files') diff --git a/test/files/run/all-overridden.check b/test/files/run/all-overridden.check new file mode 100644 index 0000000000..1b620b1176 --- /dev/null +++ b/test/files/run/all-overridden.check @@ -0,0 +1 @@ +method g diff --git a/test/files/run/all-overridden.scala b/test/files/run/all-overridden.scala new file mode 100644 index 0000000000..1b798ef748 --- /dev/null +++ b/test/files/run/all-overridden.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe._ + +object Test { + trait Foo { def f: Int = 5 ; def g: Int } + trait Bar extends Foo { def f: Int ; def g: Int = 5 } + + def main(args: Array[String]): Unit = { + // We should see g, but not f or $init$. + typeOf[Bar].declarations.toList.flatMap(_.allOverriddenSymbols) foreach println + } +} -- cgit v1.2.3