Skip to content
This repository
Browse code

Merge pull request #1859 from retronym/ticket/6912

SI-6912 Avoid a typer cycle in overload resolution.
  • Loading branch information...
commit 5d65772762072aa950a488c666673dc248b01d6d 2 parents 9ea0a20 + 7a23562
Paul Phillips authored January 12, 2013
7  src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -1512,6 +1512,13 @@ trait Infer extends Checkable {
1512 1512
         } else if (!competing.isEmpty) {
1513 1513
           if (noAlternatives) NoBestExprAlternativeError(tree, pt, isSecondTry)
1514 1514
           else if (!pt.isErroneous) AmbiguousExprAlternativeError(tree, pre, best, competing.head, pt, isSecondTry)
  1515
+          else {
  1516
+            // SI-6912 Don't give up and leave an OverloadedType on the tree.
  1517
+            //         Originally I wrote this as `if (secondTry) ... `, but `tryTwice` won't attempt the second try
  1518
+            //         unless an error is issued. We're not issuing an error, in the assumption that it would be
  1519
+            //         spurious in light of the erroneous expected type
  1520
+            setError(tree)
  1521
+          }
1515 1522
         } else {
1516 1523
 //          val applicable = alts1 filter (alt =>
1517 1524
 //            global.typer.infer.isWeaklyCompatible(pre.memberType(alt), pt))
4  test/files/neg/t6912.check
... ...
@@ -0,0 +1,4 @@
  1
+t6912.scala:8: error: not found: type Xxxx
  2
+  def test[T]: Xxxx = Foo1[T]
  3
+               ^
  4
+one error found
9  test/files/neg/t6912.scala
... ...
@@ -0,0 +1,9 @@
  1
+object Foo1 {
  2
+  def apply[T](a: Int = 0): Nothing = sys.error("")
  3
+  def apply[T](z: String = ""): Nothing = sys.error("")
  4
+}
  5
+
  6
+object Test {
  7
+  // Triggered a cycle in Typers#adapt
  8
+  def test[T]: Xxxx = Foo1[T]
  9
+}

0 notes on commit 5d65772

Please sign in to comment.
Something went wrong with that request. Please try again.