Skip to content

Commit 65980ea

Browse files
authored
Merge pull request scala#5968 from Jasper-M/topic/t5355
Fix 5355: wrong error message for cyclic structural types
2 parents a6e7134 + 6a3ec51 commit 65980ea

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,9 @@ trait TypeDiagnostics {
714714
* to a cyclic reference, and None otherwise.
715715
*/
716716
def cyclicReferenceMessage(sym: Symbol, tree: Tree) = condOpt(tree) {
717-
case ValDef(_, _, tpt, _) if tpt.tpe == null => "recursive "+sym+" needs type"
718-
case DefDef(_, _, _, _, tpt, _) if tpt.tpe == null => List(cyclicAdjective(sym), sym, "needs result type") mkString " "
719-
case Import(expr, selectors) =>
717+
case ValDef(_, _, TypeTree(), _) => "recursive "+sym+" needs type"
718+
case DefDef(_, _, _, _, TypeTree(), _) => List(cyclicAdjective(sym), sym, "needs result type") mkString " "
719+
case Import(expr, selectors) =>
720720
( "encountered unrecoverable cycle resolving import." +
721721
"\nNote: this is often due in part to a class depending on a definition nested within its companion." +
722722
"\nIf applicable, you may wish to try moving some members into another object."

test/files/neg/t5355.check

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
t5355.scala:2: error: illegal cyclic reference involving method a
2+
type A = { def a(b: A): A }
3+
^
4+
t5355.scala:3: error: illegal cyclic reference involving method a
5+
type B = { def a: B }
6+
^
7+
t5355.scala:4: error: illegal cyclic reference involving method a
8+
type C = { def a(b: C): AnyRef }
9+
^
10+
t5355.scala:5: error: illegal cyclic reference involving value a
11+
type D = { val a: D }
12+
^
13+
t5355.scala:6: error: illegal cyclic reference involving method a
14+
val e: { def a: e.type }
15+
^
16+
5 errors found

test/files/neg/t5355.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait Test {
2+
type A = { def a(b: A): A }
3+
type B = { def a: B }
4+
type C = { def a(b: C): AnyRef }
5+
type D = { val a: D }
6+
val e: { def a: e.type }
7+
}

0 commit comments

Comments
 (0)