Skip to content

Commit 83feb86

Browse files
committed
SI-7985 Typecheck args after failure to typecheck function
`missing1.foo(missing2)` now reports `missing1` and `missing2` as not found. Previously, only the first was reported. The arguments are typed with an expected type ErrorType. We propagate this through as the inferred type of anonymous function parameters to avoid issuing cascading "missing parameter type" errors in code like: scala> Nil.mapp(x => abracadabra) <console>:8: error: value mapp is not a member of object Nil Nil.mapp(x => abracadabra) ^ <console>:8: error: not found: value abracadabra Nil.mapp(x => abracadabra) ^ This was in response to unwanted changes in the output of existing neg tests; no new test is added. Similarly, we refine the errors in neg/t6436b.scala by to avoid cascaded errors after: type mismatch; found: StringContext, required: ?{def q: ?}
1 parent 7e4a97e commit 83feb86

File tree

11 files changed

+94
-13
lines changed

11 files changed

+94
-13
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,20 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
8181
}
8282
@inline final def orElse[T1 >: T](f: Seq[AbsTypeError] => T1): T1 = this match {
8383
case SilentResultValue(value) => value
84-
case s : SilentTypeError => f(s.errors)
84+
case s : SilentTypeError => f(s.reportableErrors)
8585
}
8686
}
87-
class SilentTypeError private(val errors: Seq[AbsTypeError]) extends SilentResult[Nothing] {
87+
class SilentTypeError private(val errors: List[AbsTypeError]) extends SilentResult[Nothing] {
8888
def err: AbsTypeError = errors.head
89+
def reportableErrors = errors match {
90+
case (e1: AmbiguousImplicitTypeError) +: _ =>
91+
List(e1) // DRYer error reporting for neg/t6436b.scala
92+
case all =>
93+
all
94+
}
8995
}
9096
object SilentTypeError {
91-
def apply(errors: AbsTypeError*): SilentTypeError = new SilentTypeError(errors)
97+
def apply(errors: AbsTypeError*): SilentTypeError = new SilentTypeError(errors.toList)
9298
def unapply(error: SilentTypeError): Option[AbsTypeError] = error.errors.headOption
9399
}
94100

@@ -2714,7 +2720,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
27142720
val FunctionSymbol = FunctionClass(numVparams)
27152721
val (argpts, respt) = pt baseType FunctionSymbol match {
27162722
case TypeRef(_, FunctionSymbol, args :+ res) => (args, res)
2717-
case _ => (fun.vparams map (_ => NoType), WildcardType)
2723+
case _ => (fun.vparams map (_ => if (pt == ErrorType) ErrorType else NoType), WildcardType)
27182724
}
27192725
if (argpts.lengthCompare(numVparams) != 0)
27202726
WrongNumberOfParametersError(fun, argpts)
@@ -4278,8 +4284,12 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
42784284
tryTypedApply(fun2, args)
42794285
else
42804286
doTypedApply(tree, fun2, args, mode, pt)
4281-
case SilentTypeError(err) =>
4282-
onError({ issue(err); setError(tree) })
4287+
case err: SilentTypeError =>
4288+
onError({
4289+
err.reportableErrors foreach issue
4290+
args foreach (arg => typed(arg, mode, ErrorType))
4291+
setError(tree)
4292+
})
42834293
}
42844294
}
42854295

test/files/neg/any-vs-anyref.check

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,28 @@ Such types can participate in value classes, but instances
3636
cannot appear in singleton types or in reference comparisons.
3737
def foo5(x: Quux with Product) = (x eq "abc") && ("abc" eq x)
3838
^
39+
any-vs-anyref.scala:10: error: type mismatch;
40+
found : Quux with Product
41+
required: AnyRef
42+
Note that the parents of this type (Quux, Product) extend Any, not AnyRef.
43+
Such types can participate in value classes, but instances
44+
cannot appear in singleton types or in reference comparisons.
45+
def foo5(x: Quux with Product) = (x eq "abc") && ("abc" eq x)
46+
^
3947
any-vs-anyref.scala:11: error: value eq is not a member of Quux with Product{def f: Int}
4048
Note that the parents of this type (Quux, Product) extend Any, not AnyRef.
4149
Such types can participate in value classes, but instances
4250
cannot appear in singleton types or in reference comparisons.
4351
def foo6(x: Quux with Product { def f: Int }) = (x eq "abc") && ("abc" eq x)
4452
^
53+
any-vs-anyref.scala:11: error: type mismatch;
54+
found : Quux with Product{def f: Int}
55+
required: AnyRef
56+
Note that the parents of this type (Quux, Product) extend Any, not AnyRef.
57+
Such types can participate in value classes, but instances
58+
cannot appear in singleton types or in reference comparisons.
59+
def foo6(x: Quux with Product { def f: Int }) = (x eq "abc") && ("abc" eq x)
60+
^
4561
any-vs-anyref.scala:12: error: type mismatch;
4662
found : Quux with Product{def eq(other: String): Boolean}
4763
required: AnyRef
@@ -61,4 +77,4 @@ any-vs-anyref.scala:27: error: type mismatch;
6177
required: Quux{def g(x: Int): Int}
6278
f(new Quux { def g(x: String) = x })
6379
^
64-
9 errors found
80+
11 errors found

test/files/neg/applydynamic_sip.check

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ applydynamic_sip.scala:7: error: applyDynamic does not support passing a vararg
44
applydynamic_sip.scala:8: error: applyDynamicNamed does not support passing a vararg parameter
55
qual.sel(arg = a, a2: _*)
66
^
7+
applydynamic_sip.scala:8: error: not found: value arg
8+
qual.sel(arg = a, a2: _*)
9+
^
710
applydynamic_sip.scala:9: error: applyDynamicNamed does not support passing a vararg parameter
811
qual.sel(arg, arg2 = "a2", a2: _*)
912
^
13+
applydynamic_sip.scala:9: error: not found: value arg
14+
qual.sel(arg, arg2 = "a2", a2: _*)
15+
^
16+
applydynamic_sip.scala:9: error: not found: value arg2
17+
qual.sel(arg, arg2 = "a2", a2: _*)
18+
^
1019
applydynamic_sip.scala:18: error: type mismatch;
1120
found : String("sel")
1221
required: Int
@@ -28,6 +37,9 @@ error after rewriting to Test.this.bad1.applyDynamicNamed("sel")
2837
possible cause: maybe a wrong Dynamic method signature?
2938
bad1.sel(a = 1)
3039
^
40+
applydynamic_sip.scala:20: error: reassignment to val
41+
bad1.sel(a = 1)
42+
^
3143
applydynamic_sip.scala:21: error: type mismatch;
3244
found : String("sel")
3345
required: Int
@@ -50,9 +62,12 @@ error after rewriting to Test.this.bad2.applyDynamicNamed("sel")
5062
possible cause: maybe a wrong Dynamic method signature?
5163
bad2.sel(a = 1)
5264
^
65+
applydynamic_sip.scala:31: error: reassignment to val
66+
bad2.sel(a = 1)
67+
^
5368
applydynamic_sip.scala:32: error: Int does not take parameters
5469
error after rewriting to Test.this.bad2.updateDynamic("sel")
5570
possible cause: maybe a wrong Dynamic method signature?
5671
bad2.sel = 1
5772
^
58-
11 errors found
73+
16 errors found
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Impls_Macros_Test_1.scala:36: error: macro implementation not found: foo
1+
Impls_Macros_Test_1.scala:36: error: macro implementation not found: quux
22
(the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
33
println(foo(2) + Macros.bar(2) * new Macros().quux(4))
4-
^
4+
^
55
one error found

test/files/neg/reflection-names-neg.check

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ Note that implicit conversions are not applicable because they are ambiguous:
77
are possible conversion functions from String("abc") to reflect.runtime.universe.Name
88
val x2 = ("abc": Name) drop 1 // error
99
^
10-
one error found
10+
reflection-names-neg.scala:5: error: value drop is not a member of reflect.runtime.universe.Name
11+
val x2 = ("abc": Name) drop 1 // error
12+
^
13+
two errors found

test/files/neg/t512.check

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
t512.scala:3: error: not found: value something
22
val xxx = something ||
33
^
4-
one error found
4+
t512.scala:4: error: not found: value something_else
5+
something_else;
6+
^
7+
two errors found

test/files/neg/t5761.check

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ Unspecified value parameter x.
1313
t5761.scala:13: error: not found: type Tread
1414
new Tread("sth") { }.run()
1515
^
16-
four errors found
16+
t5761.scala:13: error: value run is not a member of AnyRef
17+
new Tread("sth") { }.run()
18+
^
19+
5 errors found

test/files/neg/t7895c.check

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
t7895c.scala:2: error: not found: value bong
2+
def booboo = bong + booble + bippity - bazingo
3+
^
4+
t7895c.scala:2: error: not found: value booble
5+
def booboo = bong + booble + bippity - bazingo
6+
^
7+
t7895c.scala:2: error: not found: value bippity
8+
def booboo = bong + booble + bippity - bazingo
9+
^
10+
t7895c.scala:2: error: not found: value bazingo
11+
def booboo = bong + booble + bippity - bazingo
12+
^
13+
four errors found

test/files/neg/t7895c.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A {
2+
def booboo = bong + booble + bippity - bazingo
3+
}

test/files/run/constrained-types.check

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ scala> val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
138138
<console>:8: error: not found: value e
139139
val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
140140
^
141+
<console>:8: error: not found: value f
142+
val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
143+
^
144+
<console>:8: error: not found: value g
145+
val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
146+
^
147+
<console>:8: error: not found: value h
148+
val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
149+
^
141150

142151
scala>
143152

0 commit comments

Comments
 (0)