Skip to content

Commit b34df4d

Browse files
committed
Fix InferExpectedTypeSuite.list with Apply fixes
1 parent 0b4e677 commit b34df4d

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Applications.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ trait Applications extends Compatibility {
571571
fail(TypeMismatch(methType.resultType, resultType, None))
572572

573573
// match all arguments with corresponding formal parameters
574-
matchArgs(orderedArgs, methType.paramInfos, 0)
574+
if success then matchArgs(orderedArgs, methType.paramInfos, 0)
575575
case _ =>
576576
if (methType.isError) ok = false
577577
else fail(em"$methString does not take parameters")
@@ -666,7 +666,7 @@ trait Applications extends Compatibility {
666666
* @param n The position of the first parameter in formals in `methType`.
667667
*/
668668
def matchArgs(args: List[Arg], formals: List[Type], n: Int): Unit =
669-
if (success) formals match {
669+
formals match {
670670
case formal :: formals1 =>
671671

672672
def checkNoVarArg(arg: Arg) =
@@ -878,7 +878,9 @@ trait Applications extends Compatibility {
878878
init()
879879

880880
def addArg(arg: Tree, formal: Type): Unit =
881-
typedArgBuf += adapt(arg, formal.widenExpr)
881+
val typedArg = adapt(arg, formal.widenExpr)
882+
typedArgBuf += typedArg
883+
ok = ok & !typedArg.tpe.isError
882884

883885
def makeVarArg(n: Int, elemFormal: Type): Unit = {
884886
val args = typedArgBuf.takeRight(n).toList
@@ -943,7 +945,7 @@ trait Applications extends Compatibility {
943945
var typedArgs = typedArgBuf.toList
944946
def app0 = cpy.Apply(app)(normalizedFun, typedArgs) // needs to be a `def` because typedArgs can change later
945947
val app1 =
946-
if (!success || typedArgs.exists(_.tpe.isError)) app0.withType(UnspecifiedErrorType)
948+
if !success then app0.withType(UnspecifiedErrorType)
947949
else {
948950
if isJavaAnnotConstr(methRef.symbol) then
949951
// #19951 Make sure all arguments are NamedArgs for Java annotations

Diff for: compiler/src/dotty/tools/dotc/util/Signatures.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ object Signatures {
651651
*
652652
* @param err The error message to inspect.
653653
* @param params The parameters that were given at the call site.
654-
* @param alreadyCurried Index of paramss we are currently in.
654+
* @param paramssIndex Index of paramss we are currently in.
655655
*
656656
* @return A pair composed of the index of the best alternative (0 if no alternatives
657657
* were found), and the list of alternatives.

Diff for: presentation-compiler/test/dotty/tools/pc/tests/InferExpectedTypeSuite.scala

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class InferExpectedTypeSuite extends BasePCSuite:
5555
|""".stripMargin
5656
)
5757

58-
@Ignore("Not handled correctly.")
5958
@Test def list =
6059
check(
6160
"""|val i: List[Int] = List(@@)

Diff for: presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala

+53-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools.pc.tests.signaturehelp
22

33
import dotty.tools.pc.base.BaseSignatureHelpSuite
44

5-
import org.junit.Test
5+
import org.junit.{ Ignore, Test }
66

77
class SignatureHelpSuite extends BaseSignatureHelpSuite:
88

@@ -253,6 +253,20 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite:
253253
)
254254

255255
@Test def `tparam5` =
256+
check(
257+
"""
258+
|object a {
259+
| List[Int](1).lengthCompare(@@)
260+
|}
261+
""".stripMargin,
262+
"""|lengthCompare(len: Int): Int
263+
| ^^^^^^^^
264+
|lengthCompare(that: Iterable[?]): Int
265+
|""".stripMargin
266+
)
267+
268+
@Ignore("See if applyCallInfo can still inform on lengthCompare's sig, even if recv is in error")
269+
@Test def `tparam5_TypeMismatch` =
256270
check(
257271
"""
258272
|object a {
@@ -265,6 +279,31 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite:
265279
|""".stripMargin
266280
)
267281

282+
@Test def `tparam5_nonvarargs` =
283+
check(
284+
"""
285+
|object a {
286+
| Option[Int](1).getOrElse(@@)
287+
|}
288+
""".stripMargin,
289+
"""|getOrElse[B >: Int](default: => B): B
290+
| ^^^^^^^^^^^^^
291+
|""".stripMargin
292+
)
293+
294+
@Ignore("Similar to `tparam5_TypeMismatch`")
295+
@Test def `tparam5_nonvarargs_TypeMismatch` =
296+
check(
297+
"""
298+
|object a {
299+
| Option[String](1).getOrElse(@@)
300+
|}
301+
""".stripMargin,
302+
"""|getOrElse[B >: String](default: => B): B
303+
| ^^^^^^^^^^^^^
304+
|""".stripMargin
305+
)
306+
268307
@Test def `error1` =
269308
check(
270309
"""
@@ -547,6 +586,19 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite:
547586
)
548587

549588
@Test def `last-arg1` =
589+
check(
590+
"""
591+
|object A {
592+
| List[Int](1).map(a => @@)
593+
|}
594+
""".stripMargin,
595+
"""|map[B](f: Int => B): List[B]
596+
| ^^^^^^^^^^^
597+
|""".stripMargin
598+
)
599+
600+
@Ignore("Similar to `tparam5_TypeMismatch`")
601+
@Test def `last-arg1_TypeMismatch` =
550602
check(
551603
"""
552604
|object A {

0 commit comments

Comments
 (0)