From bdb0ac0fe55260d5ee5e14a963b73bf7d9166430 Mon Sep 17 00:00:00 2001 From: Mirco Dotta Date: Mon, 2 Dec 2013 14:57:53 +0100 Subject: SI-4827 Test to demonstrate wrong position of constructor default arg As demonstrated by the attached test, hyperlinking on constructor's default arg doesn't work (the returned tree is the parameter tree, i.e., `f`, which is of course wrong). Printing the tree reveals the issue: `` [[syntax trees at end of typer]] // Foo.scala [0:63]package [0:0] { [0:37]class Baz extends [9:37][39]scala.AnyRef { [10:31] private[this] val f: [14]Int = _; [14] def f: [14]Int = [14][14]Baz.this.f; [39]def ([14]f: [17] = [30]B.a): [9]Baz = [39]{ [39][39][39]Baz.super.(); [9]() } }; [6] object Baz extends [6][6]AnyRef { [6]def (): [9]Baz.type = [6]{ [6][6][6]Baz.super.(); [9]() }; [14] def $default$1: [14]Int = [30]B.a }; [39:63]object B extends [48:63][63]scala.AnyRef { [63]def (): [48]B.type = [63]{ [63][63][63]B.super.(); [48]() }; [52:61]private[this] val a: [56]Int = [60:61]2; [56] def a: [56]Int = [56][56]B.this.a } } `` In short, the default argument in `` (the constructor) has an offset position, while we would expect it to have a range position. Therefore, when locating a tree for any position between (start=) 10 and (end=) 31, the paramaccessor tree `f` is returned. The next commit will correct the problem. --- test/files/presentation/t4287.check | 11 +++++++++++ test/files/presentation/t4287/Test.scala | 3 +++ test/files/presentation/t4287/src/Foo.scala | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 test/files/presentation/t4287.check create mode 100644 test/files/presentation/t4287/Test.scala create mode 100644 test/files/presentation/t4287/src/Foo.scala (limited to 'test/files/presentation') diff --git a/test/files/presentation/t4287.check b/test/files/presentation/t4287.check new file mode 100644 index 0000000000..80c3e2fb23 --- /dev/null +++ b/test/files/presentation/t4287.check @@ -0,0 +1,11 @@ +reload: Foo.scala + +askHyperlinkPos for `f ` at (1,24) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `f ` at (1,15) Foo.scala +================================================================================ + +askHyperlinkPos for `f ` at (1,31) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `f ` at (1,15) Foo.scala +================================================================================ diff --git a/test/files/presentation/t4287/Test.scala b/test/files/presentation/t4287/Test.scala new file mode 100644 index 0000000000..bec1131c4c --- /dev/null +++ b/test/files/presentation/t4287/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/t4287/src/Foo.scala b/test/files/presentation/t4287/src/Foo.scala new file mode 100644 index 0000000000..a744eaabe2 --- /dev/null +++ b/test/files/presentation/t4287/src/Foo.scala @@ -0,0 +1,5 @@ +class Baz(val f: Int = B/*#*/.a/*#*/) + +object B { + val a = 2 +} -- cgit v1.2.3