Skip to content

Commit 9156761

Browse files
authored
Backport "Record failures to adapt application arguments" (#18378)
Backports #18269 Duplicate of #18372 that was autoclosed by github.
2 parents 7b4d3f0 + 48c994c commit 9156761

14 files changed

+89
-20
lines changed

compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
344344
if newSet.isEmpty then deps.remove(referenced)
345345
else deps.updated(referenced, newSet)
346346

347-
def traverse(t: Type) = t match
347+
def traverse(t: Type) = try
348+
t match
348349
case param: TypeParamRef =>
349350
if hasBounds(param) then
350351
if variance >= 0 then coDeps = update(coDeps, param)
@@ -356,6 +357,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
356357
seen += tp
357358
traverse(tp.ref)
358359
case _ => traverseChildren(t)
360+
catch case ex: Throwable => handleRecursive("adjust", t.show, ex)
359361
end Adjuster
360362

361363
/** Adjust dependencies to account for the delta of previous entry `prevEntry`

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
640640
else if (pos.source.exists) s"${pos.source.file.name}:${pos.line + 1}"
641641
else s"(no source file, offset = ${pos.span.point})"
642642

643+
def toText(cand: Candidate): Text =
644+
"Cand("
645+
~ toTextRef(cand.ref)
646+
~ (if cand.isConversion then " conv" else "")
647+
~ (if cand.isExtension then " ext" else "")
648+
~ Str(" L" + cand.level) ~ ")"
649+
643650
def toText(result: SearchResult): Text = result match {
644651
case result: SearchSuccess =>
645652
"SearchSuccess: " ~ toText(result.ref) ~ " via " ~ toText(result.tree)

compiler/src/dotty/tools/dotc/printing/Printer.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Texts._, ast.Trees._
77
import Types.{Type, SingletonType, LambdaParam},
88
Symbols.Symbol, Scopes.Scope, Constants.Constant,
99
Names.Name, Denotations._, Annotations.Annotation, Contexts.Context
10-
import typer.Implicits.SearchResult
10+
import typer.Implicits.*
1111
import util.SourcePosition
1212
import typer.ImportInfo
1313

@@ -153,6 +153,9 @@ abstract class Printer {
153153
/** Textual representation of source position */
154154
def toText(pos: SourcePosition): Text
155155

156+
/** Textual representation of implicit candidates. */
157+
def toText(cand: Candidate): Text
158+
156159
/** Textual representation of implicit search result */
157160
def toText(result: SearchResult): Text
158161

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ trait Applications extends Compatibility {
844844
var typedArgs = typedArgBuf.toList
845845
def app0 = cpy.Apply(app)(normalizedFun, typedArgs) // needs to be a `def` because typedArgs can change later
846846
val app1 =
847-
if (!success) app0.withType(UnspecifiedErrorType)
847+
if (!success || typedArgs.exists(_.tpe.isError)) app0.withType(UnspecifiedErrorType)
848848
else {
849849
if !sameSeq(args, orderedArgs)
850850
&& !isJavaAnnotConstr(methRef.symbol)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ object Implicits:
4949
}
5050

5151
/** Both search candidates and successes are references with a specific nesting level. */
52-
sealed trait RefAndLevel {
52+
sealed trait RefAndLevel extends Showable {
5353
def ref: TermRef
5454
def level: Int
5555
}
5656

5757
/** An eligible implicit candidate, consisting of an implicit reference and a nesting level */
58-
case class Candidate(implicitRef: ImplicitRef, kind: Candidate.Kind, level: Int) extends RefAndLevel {
58+
case class Candidate(implicitRef: ImplicitRef, kind: Candidate.Kind, level: Int) extends RefAndLevel with Showable {
5959
def ref: TermRef = implicitRef.underlyingRef
6060

6161
def isExtension = (kind & Candidate.Extension) != 0
6262
def isConversion = (kind & Candidate.Conversion) != 0
63+
64+
def toText(printer: Printer): Text = printer.toText(this)
6365
}
6466
object Candidate {
6567
type Kind = Int

tests/neg-macros/i6762.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import scala.quoted.*
22

33
type G[X]
44
case class Foo[T](x: T)
5-
def f(word: String)(using Quotes): Expr[Foo[G[String]]] = '{Foo(${Expr(word)})} // error // error
5+
def f(word: String)(using Quotes): Expr[Foo[G[String]]] = '{Foo(${Expr(word)})} // error

tests/neg/enum-values.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
|
2525
| failed with:
2626
|
27-
| Found: Array[example.Tag[?]]
28-
| Required: Array[example.ListLike[?]]
27+
| Found: example.ListLike.type
28+
| Required: Nothing
2929
-- [E008] Not Found Error: tests/neg/enum-values.scala:34:52 -----------------------------------------------------------
3030
34 | val typeCtorsK: Array[TypeCtorsK[?]] = TypeCtorsK.values // error
3131
| ^^^^^^^^^^^^^^^^^
@@ -38,8 +38,8 @@
3838
|
3939
| failed with:
4040
|
41-
| Found: Array[example.Tag[?]]
42-
| Required: Array[example.TypeCtorsK[?[_$1]]]
41+
| Found: example.TypeCtorsK.type
42+
| Required: Nothing
4343
-- [E008] Not Found Error: tests/neg/enum-values.scala:36:6 ------------------------------------------------------------
4444
36 | Tag.valueOf("Int") // error
4545
| ^^^^^^^^^^^

tests/neg/enumsAccess.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ object test5 {
6363
enum E5[T](x: T) {
6464
case C3() extends E5[INT](defaultX)// error: illegal reference // error: illegal reference
6565
case C4 extends E5[INT](defaultX) // error: illegal reference // error: illegal reference
66-
case C5 extends E5[E5[_]](E5.this) // error: type mismatch
66+
case C5 extends E5[E5[_]](E5.this) // error: cannot be instantiated // error: conflicting base types // error: type mismatch
6767
}
6868

6969
object E5 {

tests/neg/i6779.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| value f is not a member of T.
1212
| An extension method was tried, but could not be fully constructed:
1313
|
14-
| Test.f[G[T]](x)(given_Stuff)
14+
| Test.f[G[T]](x)
1515
|
1616
| failed with:
1717
|

tests/neg/recursive-lower-constraint.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ class Bar extends Foo[Bar]
33

44
class A {
55
def foo[T <: Foo[T], U >: Foo[T] <: T](x: T): T = x
6-
foo(new Bar) // error
6+
foo(new Bar) // error // error
77
}

0 commit comments

Comments
 (0)