From 7c81959d724a6565c00b86591d54c195d8bed1de Mon Sep 17 00:00:00 2001 From: ghik Date: Wed, 17 Sep 2014 20:45:01 +0200 Subject: SI-8459 fix incorrect positions for incomplete selection trees The mentioned issue is a presentation compiler issue, but its root cause is a bug in the parser which incorrectly assigned positions to incomplete selection trees (i.e. selections that lack an indentifier after dot and have some whitespace instead). In detail: for such incomplete selection trees, the "point" of the position should be immediately after the dot but instead was at the start of next token after the dot. For range positions, this caused a pathological situation where the "point" was greater than the "end" of the position. This position is later used by the typechecker during resolution of dynamic calls and causes it to crash. Of course, because a syntactically incorrect code is required for the bug to manifest, it only happens in the presentation compiler. --- test/files/presentation/t8459.check | 14 ++++++++++++++ test/files/presentation/t8459/Test.scala | 3 +++ .../presentation/t8459/src/IncompleteDynamicSelect.scala | 14 ++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 test/files/presentation/t8459.check create mode 100644 test/files/presentation/t8459/Test.scala create mode 100644 test/files/presentation/t8459/src/IncompleteDynamicSelect.scala (limited to 'test/files/presentation') diff --git a/test/files/presentation/t8459.check b/test/files/presentation/t8459.check new file mode 100644 index 0000000000..336c147141 --- /dev/null +++ b/test/files/presentation/t8459.check @@ -0,0 +1,14 @@ +reload: IncompleteDynamicSelect.scala + +askType at IncompleteDynamicSelect.scala(12,2) +================================================================================ +[response] askTypeAt (12,2) +scala.AnyRef { + def (): Foo = { + Foo.super.(); + () + }; + private[this] val bar: F = new F(); + Foo.this.bar.("") +} +================================================================================ diff --git a/test/files/presentation/t8459/Test.scala b/test/files/presentation/t8459/Test.scala new file mode 100644 index 0000000000..bec1131c4c --- /dev/null +++ b/test/files/presentation/t8459/Test.scala @@ -0,0 +1,3 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest + +object Test extends InteractiveTest \ No newline at end of file diff --git a/test/files/presentation/t8459/src/IncompleteDynamicSelect.scala b/test/files/presentation/t8459/src/IncompleteDynamicSelect.scala new file mode 100644 index 0000000000..61976fe2f9 --- /dev/null +++ b/test/files/presentation/t8459/src/IncompleteDynamicSelect.scala @@ -0,0 +1,14 @@ +import scala.language.dynamics + +class F extends Dynamic { + def applyDynamic(name: String)(args: Any*) = + s"method '$name' called with arguments ${args.mkString("'", "', '", "'")}" +} + +class Foo { + val bar = new F + + bar. //note whitespace after dot + /*?*/ //force typechecking +} + -- cgit v1.2.3