Skip to content

Commit f781b02

Browse files
dwijnandWojciechMazur
authored andcommitted
Fix InferExpectedTypeSuite.list with Apply fixes
[Cherry-picked b34df4d]
1 parent 9677889 commit f781b02

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ trait Applications extends Compatibility {
517517
fail(TypeMismatch(methType.resultType, resultType, None))
518518

519519
// match all arguments with corresponding formal parameters
520-
matchArgs(orderedArgs, methType.paramInfos, 0)
520+
if success then matchArgs(orderedArgs, methType.paramInfos, 0)
521521
case _ =>
522522
if (methType.isError) ok = false
523523
else fail(em"$methString does not take parameters")
@@ -595,7 +595,7 @@ trait Applications extends Compatibility {
595595
* @param n The position of the first parameter in formals in `methType`.
596596
*/
597597
def matchArgs(args: List[Arg], formals: List[Type], n: Int): Unit =
598-
if (success) formals match {
598+
formals match {
599599
case formal :: formals1 =>
600600

601601
def checkNoVarArg(arg: Arg) =
@@ -807,7 +807,9 @@ trait Applications extends Compatibility {
807807
init()
808808

809809
def addArg(arg: Tree, formal: Type): Unit =
810-
typedArgBuf += adapt(arg, formal.widenExpr)
810+
val typedArg = adapt(arg, formal.widenExpr)
811+
typedArgBuf += typedArg
812+
ok = ok & !typedArg.tpe.isError
811813

812814
def makeVarArg(n: Int, elemFormal: Type): Unit = {
813815
val args = typedArgBuf.takeRight(n).toList
@@ -872,7 +874,7 @@ trait Applications extends Compatibility {
872874
var typedArgs = typedArgBuf.toList
873875
def app0 = cpy.Apply(app)(normalizedFun, typedArgs) // needs to be a `def` because typedArgs can change later
874876
val app1 =
875-
if (!success || typedArgs.exists(_.tpe.isError)) app0.withType(UnspecifiedErrorType)
877+
if !success then app0.withType(UnspecifiedErrorType)
876878
else {
877879
if !sameSeq(args, orderedArgs)
878880
&& !isJavaAnnotConstr(methRef.symbol)

compiler/src/dotty/tools/dotc/util/Signatures.scala

Lines changed: 1 addition & 1 deletion
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.

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

Lines changed: 0 additions & 1 deletion
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(@@)

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

Lines changed: 53 additions & 1 deletion
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)