Skip to content

Commit d521be5

Browse files
authored
Record failures to adapt application arguments (#18269)
In tests/pos/i18163.scala, we don't want the ambiguous implicit of `Inv[J]` to cause the selection of `LogOps` to fail. The logic is there because it think the user's implicits "seem to be used to implement a local failure in order to negate an implicit search". But that's not the case here. The regular arguments aren't correct to start with (type kindness error), so we shouldn't even get to the implicit search and ambiguity.
2 parents 512fbd5 + b35f85f commit d521be5

File tree

17 files changed

+105
-24
lines changed

17 files changed

+105
-24
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
@@ -641,6 +641,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
641641
else if (pos.source.exists) s"${pos.source.file.name}:${pos.line + 1}"
642642
else s"(no source file, offset = ${pos.span.point})"
643643

644+
def toText(cand: Candidate): Text =
645+
"Cand("
646+
~ toTextRef(cand.ref)
647+
~ (if cand.isConversion then " conv" else "")
648+
~ (if cand.isExtension then " ext" else "")
649+
~ Str(" L" + cand.level) ~ ")"
650+
644651
def toText(result: SearchResult): Text = result match {
645652
case result: SearchSuccess =>
646653
"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, NamedType},
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

presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTypeSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ class HoverTypeSuite extends BaseHoverSuite:
134134
|class C
135135
|object Foo:
136136
| extension [T](using A)(s: T)(using B)
137-
| def double[G](using C)(times: G) = (s.toString + s.toString) * times
137+
| def double[G <: Int](using C)(times: G) = (s.toString + s.toString) * times
138138
| end extension
139139
| given A with {}
140140
| given B with {}
141141
| given C with {}
142142
| "".<<doub@@le(1)>>
143143
|end Foo
144144
|""".stripMargin,
145-
"extension [T](using A)(s: T) def double(using B)[G](using C)(times: G): String".hover
145+
"extension [T](using A)(s: T) def double(using B)[G <: Int](using C)(times: G): String".hover
146146
)
147147

148148
@Test def `extension-methods-complex-binary` =

tests/neg-macros/i16522.check

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
-- [E007] Type Mismatch Error: tests/neg-macros/i16522.scala:10:45 -----------------------------------------------------
2-
10 | case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error
2+
10 | case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error // error // error
33
| ^^^^^^^
44
| Found: tl
55
| Required: HList
66
|
77
| longer explanation available when compiling with `-explain`
8+
-- [E006] Not Found Error: tests/neg-macros/i16522.scala:10:62 ---------------------------------------------------------
9+
10 | case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error // error // error
10+
| ^^
11+
| Not found: h1
12+
|
13+
| longer explanation available when compiling with `-explain`
14+
-- [E006] Not Found Error: tests/neg-macros/i16522.scala:10:78 ---------------------------------------------------------
15+
10 | case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error // error // error
16+
| ^^
17+
| Not found: h2
18+
|
19+
| longer explanation available when compiling with `-explain`

tests/neg-macros/i16522.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def showFirstTwoImpl(e: Expr[HList])(using Quotes): Expr[String] = {
88
e match {
99
case '{HCons($h1, HCons($h2, $_))} => '{$h1.toString ++ $h2.toString}
10-
case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error
10+
case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error // error // error
1111
case '{HCons[hd, HCons[sd, tl]]($h1, HCons($h2, $_))} => '{$h1.toString ++ $h2.toString}
1212
case _ => '{""}
1313
}

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
| ^^^^^^^^^^^

0 commit comments

Comments
 (0)