From 292435f5cac948b611671e6495b4676ddbbc4c10 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Thu, 7 Mar 2013 18:55:46 +0100 Subject: Fix SI-7224. Don't focus positions assigned to the TypeTree of a parent of a Template when the parent exists in the source. A focused position (instance of `OffsetPosition`) makes it invisible to the presentation compiler when it looks for the innermost enclosing tree of a given position (breaking hyperlinking, for example). --- .../scala/tools/nsc/typechecker/Typers.scala | 2 +- test/files/presentation/hyperlinks.check | 137 ++++++++++++++++++++- .../presentation/hyperlinks/src/SuperTypes.scala | 32 +++++ 3 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 test/files/presentation/hyperlinks/src/SuperTypes.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index fcf7ba6efb..d8493d2312 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1576,7 +1576,7 @@ trait Typers extends Modes with Adaptations with Tags { if (sarg != EmptyTree && supertpe.typeSymbol != firstParent) ConstrArgsInTraitParentTpeError(sarg, firstParent) if (!supertparams.isEmpty) - supertpt = TypeTree(cbody2.tpe) setPos supertpt.pos.focus + supertpt = TypeTree(cbody2.tpe) setPos supertpt.pos case _ => if (!supertparams.isEmpty) MissingTypeArgumentsParentTpeError(supertpt) diff --git a/test/files/presentation/hyperlinks.check b/test/files/presentation/hyperlinks.check index 85d295dd7d..1051b67e85 100644 --- a/test/files/presentation/hyperlinks.check +++ b/test/files/presentation/hyperlinks.check @@ -1,4 +1,4 @@ -reload: NameDefaultTests.scala, PatMatTests.scala +reload: NameDefaultTests.scala, PatMatTests.scala, SuperTypes.scala askHyperlinkPos for `someOtherInt` at (14,24) NameDefaultTests.scala ================================================================================ @@ -44,3 +44,138 @@ askHyperlinkPos for `y` at (25,21) PatMatTests.scala ================================================================================ [response] found askHyperlinkPos for `y` at (23,13) PatMatTests.scala ================================================================================ + +askHyperlinkPos for `BadPos` at (10,26) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `BadPos` at (2,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `BadPos` at (11,26) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `BadPos` at (2,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `Trait` at (12,25) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `Trait` at (6,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `SubTrait` at (13,28) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `SubTrait` at (7,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `Trait` at (14,25) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `Trait` at (6,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `LateralTrait` at (14,48) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `LateralTrait` at (8,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `Base` at (15,24) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `Base` at (4,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `Trait` at (15,40) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `Trait` at (6,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `LateralTrait` at (15,63) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `LateralTrait` at (8,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PBase` at (19,29) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PBase` at (17,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PTrait` at (20,33) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PTrait` at (19,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PBase` at (21,36) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PBase` at (17,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PTrait` at (23,27) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PTrait` at (19,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PSubTrait` at (24,30) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PSubTrait` at (20,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PTrait` at (25,27) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PTrait` at (19,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PLateralTrait` at (25,56) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PLateralTrait` at (21,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PBase` at (26,26) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PBase` at (17,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PTrait` at (26,48) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PTrait` at (19,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PLateralTrait` at (26,77) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PLateralTrait` at (21,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `BadPos` at (28,23) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `BadPos` at (2,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PTrait` at (29,23) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PTrait` at (19,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PSubTrait` at (30,26) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PSubTrait` at (20,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PTrait` at (31,23) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PTrait` at (19,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PLateralTrait` at (31,52) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PLateralTrait` at (21,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PBase` at (32,22) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PBase` at (17,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PTrait` at (32,44) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PTrait` at (19,7) SuperTypes.scala +================================================================================ + +askHyperlinkPos for `PLateralTrait` at (32,73) SuperTypes.scala +================================================================================ +[response] found askHyperlinkPos for `PLateralTrait` at (21,7) SuperTypes.scala +================================================================================ diff --git a/test/files/presentation/hyperlinks/src/SuperTypes.scala b/test/files/presentation/hyperlinks/src/SuperTypes.scala new file mode 100644 index 0000000000..15d16069fd --- /dev/null +++ b/test/files/presentation/hyperlinks/src/SuperTypes.scala @@ -0,0 +1,32 @@ +/** This tests that hyperlinking works for super types. See SI-7224 */ +class BadPos[A](a: A) + +class Base + +trait Trait extends Base +trait SubTrait extends Trait +trait LateralTrait extends Base + +object obj1 extends BadPos/*#*/(new Object) +object obj2 extends BadPos/*#*/[AnyRef](new Object) +object obj3 extends Trait/*#*/ +object obj4 extends SubTrait/*#*/ +object obj5 extends Trait/*#*/ with LateralTrait/*#*/ +object obj6 extends Base/*#*/ with Trait/*#*/ with LateralTrait/*#*/ + +class PBase[A] + +trait PTrait[A] extends PBase/*#*/[A] +trait PSubTrait[A] extends PTrait/*#*/[A] +trait PLateralTrait[A] extends PBase/*#*/[A] + +object pobj2 extends PTrait/*#*/[Int] +object pobj3 extends PSubTrait/*#*/[Int] +object pobj4 extends PTrait/*#*/[Int] with PLateralTrait/*#*/[Int] +object pobj5 extends PBase/*#*/[Int] with PTrait/*#*/[Int] with PLateralTrait/*#*/[Int] + +class c1 extends BadPos/*#*/(new Object) +class c2 extends PTrait/*#*/[Int] +class c3 extends PSubTrait/*#*/[Int] +class c4 extends PTrait/*#*/[Int] with PLateralTrait/*#*/[Int] +class c5 extends PBase/*#*/[Int] with PTrait/*#*/[Int] with PLateralTrait/*#*/[Int] -- cgit v1.2.3