summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/interactive/RangePositions.scala3
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/core/FindOccurrences.scala28
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerRequestsWorkingMode.scala22
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala31
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala4
-rw-r--r--test/files/neg/t5564.check4
-rw-r--r--test/files/neg/t5564.scala9
-rw-r--r--test/files/presentation/hyperlinks.check (renamed from test/files/presentation/patmat.check)12
-rw-r--r--test/files/presentation/hyperlinks.flags (renamed from test/files/presentation/patmat.flags)0
-rw-r--r--test/files/presentation/hyperlinks/Runner.scala (renamed from test/files/presentation/patmat/Runner.scala)0
-rw-r--r--test/files/presentation/hyperlinks/src/NameDefaultTests.scala16
-rw-r--r--test/files/presentation/hyperlinks/src/PatMatTests.scala (renamed from test/files/presentation/patmat/src/PatMatTests.scala)0
14 files changed, 86 insertions, 47 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/RangePositions.scala b/src/compiler/scala/tools/nsc/interactive/RangePositions.scala
index 72e5ee42ed..49ba9d0aeb 100644
--- a/src/compiler/scala/tools/nsc/interactive/RangePositions.scala
+++ b/src/compiler/scala/tools/nsc/interactive/RangePositions.scala
@@ -269,7 +269,8 @@ self: scala.tools.nsc.Global =>
protected def isEligible(t: Tree) = !t.pos.isTransparent
override def traverse(t: Tree) {
t match {
- case tt : TypeTree if tt.original != null => traverse(tt.original)
+ case tt : TypeTree if tt.original != null && (tt.pos includes tt.original.pos) =>
+ traverse(tt.original)
case _ =>
if (t.pos includes pos) {
if (isEligible(t)) last = t
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/core/FindOccurrences.scala b/src/compiler/scala/tools/nsc/interactive/tests/core/FindOccurrences.scala
deleted file mode 100644
index e2a5a3e3ee..0000000000
--- a/src/compiler/scala/tools/nsc/interactive/tests/core/FindOccurrences.scala
+++ /dev/null
@@ -1,28 +0,0 @@
-package scala.tools.nsc
-package interactive
-package tests.core
-
-import scala.tools.nsc.util.Position
-import scala.tools.nsc.util.SourceFile
-
-/** Find occurrences of `text` in the passed `sources`. */
-private[core] object FindOccurrences {
-
- def apply(sources: Seq[SourceFile])(text: String): Map[SourceFile, Seq[Position]] =
- allPositionsOf(sources, text)
-
- /** All positions of the given string in all source files. */
- private def allPositionsOf(sources: Seq[SourceFile], str: String): Map[SourceFile, Seq[Position]] =
- (for (s <- sources; p <- positionsOf(s, str)) yield p).groupBy(_.source)
-
- /** Return all positions of the given str in the given source file. */
- private def positionsOf(source: SourceFile, str: String): Seq[Position] = {
- val buf = new collection.mutable.ListBuffer[Position]
- var pos = source.content.indexOfSlice(str)
- while (pos >= 0) {
- buf += source.position(pos - 1) // we need the position before the first character of this marker
- pos = source.content.indexOfSlice(str, pos + 1)
- }
- buf.toList
- }
-} \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerRequestsWorkingMode.scala b/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerRequestsWorkingMode.scala
index c274e13976..d2baaf32c6 100644
--- a/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerRequestsWorkingMode.scala
+++ b/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerRequestsWorkingMode.scala
@@ -16,7 +16,7 @@ trait PresentationCompilerRequestsWorkingMode extends TestResources {
* ask the type at all positions marked with `TypeMarker.marker` and println the result.
*/
private def askAllSourcesAsync[T](marker: TestMarker)(askAt: Position => Response[T])(f: (Position, T) => Unit) {
- val positions = allPositionsOf(marker.marker).valuesIterator.toList.flatten
+ val positions = allPositionsOf(str = marker.marker)
val responses = for (pos <- positions) yield askAt(pos)
for ((pos, r) <- positions zip responses) withResponse(pos, r)(f)
@@ -26,13 +26,25 @@ trait PresentationCompilerRequestsWorkingMode extends TestResources {
* response before going to the next one.
*/
private def askAllSourcesSync[T](marker: TestMarker)(askAt: Position => Response[T])(f: (Position, T) => Unit) {
- val positions = allPositionsOf(marker.marker).valuesIterator.toList.flatten
+ val positions = allPositionsOf(str = marker.marker)
for (pos <- positions) withResponse(pos, askAt(pos))(f)
}
- private def allPositionsOf: String => Map[SourceFile, Seq[Position]] =
- FindOccurrences(sourceFiles) _
-
+ /** All positions of the given string in all source files. */
+ private def allPositionsOf(srcs: Seq[SourceFile] = sourceFiles, str: String): Seq[Position] =
+ for (s <- srcs; p <- positionsOf(s, str)) yield p
+
+ /** Return all positions of the given str in the given source file. */
+ private def positionsOf(source: SourceFile, str: String): Seq[Position] = {
+ val buf = new collection.mutable.ListBuffer[Position]
+ var pos = source.content.indexOfSlice(str)
+ while (pos >= 0) {
+ buf += source.position(pos - 1) // we need the position before the first character of this marker
+ pos = source.content.indexOfSlice(str, pos + 1)
+ }
+ buf.toList
+ }
+
private def withResponse[T](pos: Position, response: Response[T])(f: (Position, T) => Unit) {
/** Return the filename:line:col version of this position. */
def showPos(pos: Position): String =
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala b/src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala
index 518cb7bd76..21e90fe57f 100644
--- a/src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala
+++ b/src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala
@@ -13,7 +13,7 @@ private[tests] object SourcesCollector {
* */
def apply(base: Path, filter: SourceFilter): Array[SourceFile] = {
assert(base.isDirectory)
- base.walk.filter(filter).map(source).toArray
+ base.walk.filter(filter).map(source).toList.toArray.sortBy(_.file.name)
}
private def source(file: Path): SourceFile = source(AbstractFile.getFile(file.toFile))
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index e0f34b47c8..aea29a27dd 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -1322,7 +1322,15 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
else None
} else None
}
-
+
+ def reportError[T](body: =>T)(handler: TypeError => T): T =
+ try body
+ catch {
+ case te: TypeError =>
+ reporter.error(tree.pos, te.msg)
+ handler(te)
+ }
+
curTree = tree
tree match {
case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
@@ -1331,11 +1339,10 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
if (found.typeSymbol ne tpt.tpe.typeSymbol) {
// the ctor can be specialized
debuglog("** instantiated specialized type: " + found)
- try localTyper.typedPos(tree.pos)(New(found, transformTrees(args): _*))
- catch {
- case te: TypeError =>
- reporter.error(tree.pos, te.msg)
- super.transform(tree)
+ reportError {
+ localTyper.typedPos(tree.pos)(New(found, transformTrees(args): _*))
+ } {
+ _ => super.transform(tree)
}
} else super.transform(tree)
@@ -1493,13 +1500,21 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
})
debuglog("created special overload tree " + t)
debuglog("created " + t)
- localTyper.typed(t)
+ reportError {
+ localTyper.typed(t)
+ } {
+ _ => super.transform(tree)
+ }
case fwd @ Forward(_) =>
debuglog("forward: " + fwd + ", " + ddef)
val rhs1 = forwardCall(tree.pos, gen.mkAttributedRef(symbol.owner.thisType, fwd.target), vparamss)
debuglog("-->d completed forwarder to specialized overload: " + fwd.target + ": " + rhs1)
- localTyper.typed(deriveDefDef(tree)(_ => rhs1))
+ reportError {
+ localTyper.typed(deriveDefDef(tree)(_ => rhs1))
+ } {
+ _ => super.transform(tree)
+ }
case SpecializedAccessor(target) =>
val rhs1 = if (symbol.isGetter)
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index 90e388c30a..bef6f13bc3 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -338,7 +338,7 @@ trait NamesDefaults { self: Analyzer =>
// cannot call blockTyper.typedBlock here, because the method expr might be partially applied only
val res = blockTyper.doTypedApply(tree, expr, refArgs, mode, pt)
res.setPos(res.pos.makeTransparent)
- val block = Block(stats ::: valDefs, res).setType(res.tpe).setPos(tree.pos)
+ val block = Block(stats ::: valDefs, res).setType(res.tpe).setPos(tree.pos.makeTransparent)
context.namedApplyBlockInfo =
Some((block, NamedApplyInfo(qual, targs, vargss :+ refArgs, blockTyper)))
block
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 8c2eae1c86..08d6bd7226 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -921,7 +921,7 @@ trait Typers extends Modes with Adaptations with Taggings {
KindArityMismatchError(tree, pt)
} else tree match { // (6)
case TypeTree() => tree
- case _ => TypeTree(tree.tpe) setOriginal (tree) setPos (tree.pos)
+ case _ => TypeTree(tree.tpe) setOriginal tree
}
}
@@ -3230,7 +3230,7 @@ trait Typers extends Modes with Adaptations with Taggings {
}
if (hasError) annotationError
- else AnnotationInfo(annType, List(), nvPairs map {p => (p._1, p._2.get)}).setOriginal(Apply(typedFun, args)).setPos(ann.pos)
+ else AnnotationInfo(annType, List(), nvPairs map {p => (p._1.asInstanceOf[Name], p._2.get)}).setOriginal(Apply(typedFun, args).setPos(ann.pos)) // [Eugene+] why do we need this cast?
}
} else if (requireJava) {
reportAnnotationError(NestedAnnotationError(ann, annType))
diff --git a/test/files/neg/t5564.check b/test/files/neg/t5564.check
new file mode 100644
index 0000000000..e7e13ccc9c
--- /dev/null
+++ b/test/files/neg/t5564.check
@@ -0,0 +1,4 @@
+t5564.scala:8: error: inferred type arguments [A] do not conform to method bar's type parameter bounds [B >: A <: C]
+ def bar[B >: A <: C]: T = throw new Exception
+ ^
+one error found
diff --git a/test/files/neg/t5564.scala b/test/files/neg/t5564.scala
new file mode 100644
index 0000000000..663cf88726
--- /dev/null
+++ b/test/files/neg/t5564.scala
@@ -0,0 +1,9 @@
+
+
+
+trait C
+
+
+class Foo[@specialized(Int) T, A] {
+ def bar[B >: A <: C]: T = throw new Exception
+}
diff --git a/test/files/presentation/patmat.check b/test/files/presentation/hyperlinks.check
index 29fd8b8e68..85d295dd7d 100644
--- a/test/files/presentation/patmat.check
+++ b/test/files/presentation/hyperlinks.check
@@ -1,4 +1,14 @@
-reload: PatMatTests.scala
+reload: NameDefaultTests.scala, PatMatTests.scala
+
+askHyperlinkPos for `someOtherInt` at (14,24) NameDefaultTests.scala
+================================================================================
+[response] found askHyperlinkPos for `someOtherInt` at (12,9) NameDefaultTests.scala
+================================================================================
+
+askHyperlinkPos for `someString` at (14,45) NameDefaultTests.scala
+================================================================================
+[response] found askHyperlinkPos for `someString` at (3,7) NameDefaultTests.scala
+================================================================================
askHyperlinkPos for `CaseOne` at (12,18) PatMatTests.scala
================================================================================
diff --git a/test/files/presentation/patmat.flags b/test/files/presentation/hyperlinks.flags
index dc13682c5e..dc13682c5e 100644
--- a/test/files/presentation/patmat.flags
+++ b/test/files/presentation/hyperlinks.flags
diff --git a/test/files/presentation/patmat/Runner.scala b/test/files/presentation/hyperlinks/Runner.scala
index 3d19f2d948..3d19f2d948 100644
--- a/test/files/presentation/patmat/Runner.scala
+++ b/test/files/presentation/hyperlinks/Runner.scala
diff --git a/test/files/presentation/hyperlinks/src/NameDefaultTests.scala b/test/files/presentation/hyperlinks/src/NameDefaultTests.scala
new file mode 100644
index 0000000000..b218040fe3
--- /dev/null
+++ b/test/files/presentation/hyperlinks/src/NameDefaultTests.scala
@@ -0,0 +1,16 @@
+
+class NameDefaults {
+ val someString = "abc"
+ val someInt = 42
+
+ def foo(x: String, y: Int)(implicit logger: Int): Int = y
+
+ implicit val l = 42
+
+ def bar {
+ println()
+ val someOtherInt = 10
+
+ foo(y = someOtherInt/*#*/, x = someString/*#*/)
+ }
+}
diff --git a/test/files/presentation/patmat/src/PatMatTests.scala b/test/files/presentation/hyperlinks/src/PatMatTests.scala
index bbd0f2e7ed..bbd0f2e7ed 100644
--- a/test/files/presentation/patmat/src/PatMatTests.scala
+++ b/test/files/presentation/hyperlinks/src/PatMatTests.scala