Skip to content

Commit 094f7f9

Browse files
committed
SI-10207 Error before update conversion
Gaze deeper for errors before committing to conversion of assignment to update. The error buried in the transformed tree escapes notice of retypechecking and leaks to backend.
1 parent 5f1a638 commit 094f7f9

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4666,19 +4666,20 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
46664666
val qual1 = typedQualifier(qual)
46674667
if (treeInfo.isVariableOrGetter(qual1)) {
46684668
if (Statistics.canEnable) Statistics.stopTimer(failedOpEqNanos, opeqStart)
4669-
val erred = qual1.isErroneous || args.exists(_.isErroneous)
4669+
val erred = qual1.exists(_.isErroneous) || args.exists(_.isErroneous)
46704670
if (erred) reportError(error) else {
46714671
val convo = convertToAssignment(fun, qual1, name, args)
46724672
silent(op = _.typed1(convo, mode, pt)) match {
46734673
case SilentResultValue(t) => t
4674-
case err: SilentTypeError => reportError(SilentTypeError(advice1(convo, error.errors, err), error.warnings))
4674+
case err: SilentTypeError => reportError(
4675+
SilentTypeError(advice1(convo, error.errors, err), error.warnings)
4676+
)
46754677
}
46764678
}
4677-
}
4678-
else {
4679+
} else {
46794680
if (Statistics.canEnable) Statistics.stopTimer(failedApplyNanos, appStart)
46804681
val Apply(Select(qual2, _), args2) = tree
4681-
val erred = qual2.isErroneous || args2.exists(_.isErroneous)
4682+
val erred = qual2.exists(_.isErroneous) || args2.exists(_.isErroneous)
46824683
reportError {
46834684
if (erred) error else SilentTypeError(advice2(error.errors), error.warnings)
46844685
}

test/files/neg/t10207.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
t10207.scala:14: error: too many arguments (2) for method apply: (key: Int)scala.collection.mutable.ArrayBuffer[String] in trait MapLike
2+
m(1, (_ => empty)) ++= AB("eins", "uno")
3+
^
4+
one error found

test/files/neg/t10207.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// Was:
3+
// warning: an unexpected type representation reached the compiler backend
4+
// Now:
5+
// error: too many arguments (2) for method apply: (key: Int)scala.collection.mutable.ArrayBuffer[String] in trait MapLike
6+
7+
trait Test {
8+
import collection.mutable.{Map=>MMap, ArrayBuffer=>AB}
9+
10+
val m = MMap((1 -> AB("one")))
11+
12+
val empty = AB[String]()
13+
14+
m(1, (_ => empty)) ++= AB("eins", "uno")
15+
}
16+

0 commit comments

Comments
 (0)