From 6be9fc678b8af5df915905059fd31f0fc1d9d821 Mon Sep 17 00:00:00 2001 From: Olli Helenius Date: Thu, 19 May 2016 23:05:45 +0300 Subject: SI-9781 Don't convert erroneous expression to assignment `convertToAssignment` is triggered on a type error but it doesn't seem to really care what the error is as long as the expression can be converted to an assignment expression. This patch fixes that by checking whether the qualifier of the selection contains any errors before deciding to continue with the conversion. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 4 +++- test/files/neg/t9781.check | 4 ++++ test/files/neg/t9781.scala | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/files/neg/t9781.check create mode 100644 test/files/neg/t9781.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 329ce8c23b..1aed9c3a64 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -4494,7 +4494,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val opeqStart = if (Statistics.canEnable) Statistics.startTimer(failedOpEqNanos) else null def onError(reportError: => Tree): Tree = fun match { - case Select(qual, name) if !mode.inPatternMode && nme.isOpAssignmentName(newTermName(name.decode)) => + case Select(qual, name) + if !mode.inPatternMode && nme.isOpAssignmentName(newTermName(name.decode)) && !qual.exists(_.isErroneous) => + val qual1 = typedQualifier(qual) if (treeInfo.isVariableOrGetter(qual1)) { if (Statistics.canEnable) Statistics.stopTimer(failedOpEqNanos, opeqStart) diff --git a/test/files/neg/t9781.check b/test/files/neg/t9781.check new file mode 100644 index 0000000000..422c51013a --- /dev/null +++ b/test/files/neg/t9781.check @@ -0,0 +1,4 @@ +t9781.scala:3: error: not found: value undefinedSymbol + c(undefinedSymbol) += 1 + ^ +one error found diff --git a/test/files/neg/t9781.scala b/test/files/neg/t9781.scala new file mode 100644 index 0000000000..70234dcca5 --- /dev/null +++ b/test/files/neg/t9781.scala @@ -0,0 +1,4 @@ +object T9781 { + val c: collection.mutable.Map[Int, Int] = ??? + c(undefinedSymbol) += 1 +} -- cgit v1.2.3