From d28879042951015f0ef2d5263b7df264a13a8055 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 28 May 2014 21:46:53 +0200 Subject: SI-8596 Fix rangepos crasher with defaults, poly methods Regressed in SI-7915 / 3009a525b5 We should be deriving the position of the synthetic `Select` from `basefun1`, rather than `basefun`. In the new, enclosed test, the difference amounts to: new Container().typeParamAndDefaultArg[Any]() `------------ basefun1 --------------' `----------------- basefun ---------------' For monomorphic methods, these are one and the same, which is why `presentation/t7915` was working. I've extended that test to a polymorphic method to check that hyperlink resolution works. --- .../scala/tools/nsc/typechecker/NamesDefaults.scala | 6 +++--- test/files/pos/t8596.flags | 1 + test/files/pos/t8596.scala | 7 +++++++ test/files/presentation/t7915.check | 20 ++++++++++++++++++++ test/files/presentation/t7915/src/Foo.scala | 4 +++- 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/files/pos/t8596.flags create mode 100644 test/files/pos/t8596.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index 70f2f41ec7..307e17d97a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -175,9 +175,9 @@ trait NamesDefaults { self: Analyzer => // setSymbol below is important because the 'selected' function might be overloaded. by // assigning the correct method symbol, typedSelect will just assign the type. the reason // to still call 'typed' is to correctly infer singleton types, SI-5259. - val selectPos = - if(qual.pos.isRange && baseFun.pos.isRange) qual.pos.union(baseFun.pos).withStart(Math.min(qual.pos.end, baseFun.pos.end)) - else baseFun.pos + val selectPos = + if(qual.pos.isRange && baseFun1.pos.isRange) qual.pos.union(baseFun1.pos).withStart(Math.min(qual.pos.end, baseFun1.pos.end)) + else baseFun1.pos val f = blockTyper.typedOperator(Select(newQual, selected).setSymbol(baseFun1.symbol).setPos(selectPos)) if (funTargs.isEmpty) f else TypeApply(f, funTargs).setType(baseFun.tpe) diff --git a/test/files/pos/t8596.flags b/test/files/pos/t8596.flags new file mode 100644 index 0000000000..281f0a10cd --- /dev/null +++ b/test/files/pos/t8596.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/test/files/pos/t8596.scala b/test/files/pos/t8596.scala new file mode 100644 index 0000000000..bfed58eadf --- /dev/null +++ b/test/files/pos/t8596.scala @@ -0,0 +1,7 @@ +class TypeTreeObjects { + class Container { + def typeParamAndDefaultArg[C](name: String = ""): String = "" + } + // crashed under -Yrangepos + new Container().typeParamAndDefaultArg[Any]() +} diff --git a/test/files/presentation/t7915.check b/test/files/presentation/t7915.check index b18b4ddb55..0849aaa82b 100644 --- a/test/files/presentation/t7915.check +++ b/test/files/presentation/t7915.check @@ -9,3 +9,23 @@ askHyperlinkPos for `bar` at (7,22) Foo.scala ================================================================================ [response] found askHyperlinkPos for `bar` at (2,7) Foo.scala ================================================================================ + +askHyperlinkPos for `Bar` at (8,11) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `Bar` at (1,7) Foo.scala +================================================================================ + +askHyperlinkPos for `baz` at (8,22) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `baz` at (2,31) Foo.scala +================================================================================ + +askHyperlinkPos for `Bar` at (9,11) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `Bar` at (1,7) Foo.scala +================================================================================ + +askHyperlinkPos for `baz` at (9,22) Foo.scala +================================================================================ +[response] found askHyperlinkPos for `baz` at (2,31) Foo.scala +================================================================================ diff --git a/test/files/presentation/t7915/src/Foo.scala b/test/files/presentation/t7915/src/Foo.scala index a4166ae5b4..5c9ca36a6e 100644 --- a/test/files/presentation/t7915/src/Foo.scala +++ b/test/files/presentation/t7915/src/Foo.scala @@ -1,9 +1,11 @@ class Bar { - def bar(b: Int = 2) {} + def bar(b: Int = 2) {}; def baz[X](b: Int = 2) {} } class Foo { def foo() { new Bar/*#*/().bar/*#*/() + new Bar/*#*/().baz/*#*/[Any]() + new Bar/*#*/().baz/*#*/() } } -- cgit v1.2.3