From b0c4353ea1ad0af81cef31e460746d887ef151e2 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 2 Feb 2014 14:27:39 +0100 Subject: SI-8228 Avoid infinite loop with erroneous code, overloading `isApplicableBasedOnArity` couldn't get of the ferris wheel after as `followApply` kept insisting on another spin. scala> ErrorType nonPrivateMember nme.apply res0: $r.intp.global.Symbol = value apply scala> res0.info res1: $r.intp.global.Type = This commit makes `followApply` consider that an `ErrorType` does not contain an `apply` member. I also considered whether to do a deep check on the type (`isErroneous`), but I can't motivate this with a test. I tend to think we *shouldn't* do that: `List[${ErrorType}]` still has an `apply` member that we should follow, right? --- src/compiler/scala/tools/nsc/typechecker/Infer.scala | 1 + test/files/neg/t8228.check | 4 ++++ test/files/neg/t8228.scala | 7 +++++++ 3 files changed, 12 insertions(+) create mode 100644 test/files/neg/t8228.check create mode 100644 test/files/neg/t8228.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index dd0923a696..997fd6fc65 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -595,6 +595,7 @@ trait Infer extends Checkable { } private[typechecker] def followApply(tp: Type): Type = tp match { + case _ if tp.isError => tp // SI-8228, `ErrorType nonPrivateMember nme.apply` returns an member with an erroneous type! case NullaryMethodType(restp) => val restp1 = followApply(restp) if (restp1 eq restp) tp else restp1 diff --git a/test/files/neg/t8228.check b/test/files/neg/t8228.check new file mode 100644 index 0000000000..02eff4b1b7 --- /dev/null +++ b/test/files/neg/t8228.check @@ -0,0 +1,4 @@ +t8228.scala:4: error: recursive value foo needs type + val foo = foo(null) + ^ +one error found diff --git a/test/files/neg/t8228.scala b/test/files/neg/t8228.scala new file mode 100644 index 0000000000..19d71aeab4 --- /dev/null +++ b/test/files/neg/t8228.scala @@ -0,0 +1,7 @@ +object X { + def bar = { + def foo(x: Any) = "" + val foo = foo(null) + foo(null) // cycle in isApplicableBasedOnArity + } +} -- cgit v1.2.3