Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Record failures to adapt application arguments" #18372

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
if newSet.isEmpty then deps.remove(referenced)
else deps.updated(referenced, newSet)

def traverse(t: Type) = t match
def traverse(t: Type) = try
t match
case param: TypeParamRef =>
if hasBounds(param) then
if variance >= 0 then coDeps = update(coDeps, param)
Expand All @@ -356,6 +357,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
seen += tp
traverse(tp.ref)
case _ => traverseChildren(t)
catch case ex: Throwable => handleRecursive("adjust", t.show, ex)
end Adjuster

/** Adjust dependencies to account for the delta of previous entry `prevEntry`
Expand Down
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
else if (pos.source.exists) s"${pos.source.file.name}:${pos.line + 1}"
else s"(no source file, offset = ${pos.span.point})"

def toText(cand: Candidate): Text =
"Cand("
~ toTextRef(cand.ref)
~ (if cand.isConversion then " conv" else "")
~ (if cand.isExtension then " ext" else "")
~ Str(" L" + cand.level) ~ ")"

def toText(result: SearchResult): Text = result match {
case result: SearchSuccess =>
"SearchSuccess: " ~ toText(result.ref) ~ " via " ~ toText(result.tree)
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/Printer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Texts._, ast.Trees._
import Types.{Type, SingletonType, LambdaParam},
Symbols.Symbol, Scopes.Scope, Constants.Constant,
Names.Name, Denotations._, Annotations.Annotation, Contexts.Context
import typer.Implicits.SearchResult
import typer.Implicits.*
import util.SourcePosition
import typer.ImportInfo

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

/** Textual representation of implicit candidates. */
def toText(cand: Candidate): Text

/** Textual representation of implicit search result */
def toText(result: SearchResult): Text

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ trait Applications extends Compatibility {
var typedArgs = typedArgBuf.toList
def app0 = cpy.Apply(app)(normalizedFun, typedArgs) // needs to be a `def` because typedArgs can change later
val app1 =
if (!success) app0.withType(UnspecifiedErrorType)
if (!success || typedArgs.exists(_.tpe.isError)) app0.withType(UnspecifiedErrorType)
else {
if !sameSeq(args, orderedArgs)
&& !isJavaAnnotConstr(methRef.symbol)
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ object Implicits:
}

/** Both search candidates and successes are references with a specific nesting level. */
sealed trait RefAndLevel {
sealed trait RefAndLevel extends Showable {
def ref: TermRef
def level: Int
}

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

def isExtension = (kind & Candidate.Extension) != 0
def isConversion = (kind & Candidate.Conversion) != 0

def toText(printer: Printer): Text = printer.toText(this)
}
object Candidate {
type Kind = Int
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i6762.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import scala.quoted.*

type G[X]
case class Foo[T](x: T)
def f(word: String)(using Quotes): Expr[Foo[G[String]]] = '{Foo(${Expr(word)})} // error // error
def f(word: String)(using Quotes): Expr[Foo[G[String]]] = '{Foo(${Expr(word)})} // error
8 changes: 4 additions & 4 deletions tests/neg/enum-values.check
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
|
| failed with:
|
| Found: Array[example.Tag[?]]
| Required: Array[example.ListLike[?]]
| Found: example.ListLike.type
| Required: Nothing
-- [E008] Not Found Error: tests/neg/enum-values.scala:34:52 -----------------------------------------------------------
34 | val typeCtorsK: Array[TypeCtorsK[?]] = TypeCtorsK.values // error
| ^^^^^^^^^^^^^^^^^
Expand All @@ -38,8 +38,8 @@
|
| failed with:
|
| Found: Array[example.Tag[?]]
| Required: Array[example.TypeCtorsK[?[_$1]]]
| Found: example.TypeCtorsK.type
| Required: Nothing
-- [E008] Not Found Error: tests/neg/enum-values.scala:36:6 ------------------------------------------------------------
36 | Tag.valueOf("Int") // error
| ^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/enumsAccess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object test5 {
enum E5[T](x: T) {
case C3() extends E5[INT](defaultX)// error: illegal reference // error: illegal reference
case C4 extends E5[INT](defaultX) // error: illegal reference // error: illegal reference
case C5 extends E5[E5[_]](E5.this) // error: type mismatch
case C5 extends E5[E5[_]](E5.this) // error: cannot be instantiated // error: conflicting base types // error: type mismatch
}

object E5 {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i6779.check
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| value f is not a member of T.
| An extension method was tried, but could not be fully constructed:
|
| Test.f[G[T]](x)(given_Stuff)
| Test.f[G[T]](x)
|
| failed with:
|
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/recursive-lower-constraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ class Bar extends Foo[Bar]

class A {
def foo[T <: Foo[T], U >: Foo[T] <: T](x: T): T = x
foo(new Bar) // error
foo(new Bar) // error // error
}
6 changes: 0 additions & 6 deletions tests/neg/syntax-error-recovery.check
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@
| Not found: bam
|
| longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/syntax-error-recovery.scala:61:10 -------------------------------------------------
61 | println(bam) // error
| ^^^
| Not found: bam
|
| longer explanation available when compiling with `-explain`
-- [E129] Potential Issue Warning: tests/neg/syntax-error-recovery.scala:7:2 -------------------------------------------
6 | 2
7 | }
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/syntax-error-recovery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ object Test2:
def foo5(x: Int) =
foo2(foo2(,) // error // error

println(bam) // error
println(bam)
// error
40 changes: 40 additions & 0 deletions tests/pos/i18163.orig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import scala.language.implicitConversions

// We do have 2 `contramap` functions, one provided via `LoggerSyntax` other via `Contravariant.Ops`
// `ContravariantMonoidal` given instances are not used, and they do not match our type. Code fails when we have at least 2 instances of them
// Removal of `import catsSyntax._` allow to compile code
// Removal of `import odinSyntax.LoggerSyntax` and remaining `catsSyntax` would fail to compile the `def fails`

trait Foo[A]
trait Bar[A]

trait WriterT[F[_]: Contravariant, L, V]:
def contramap[Z](fn: Z => V): WriterT[F, L, Z] = ???
trait Logger[F[_]]
class WriterTLogger[F[_]] extends Logger[[G] =>> WriterT[F, List[String], G]]

trait ContravariantMonoidal[F[_]] extends Invariant[F] with Contravariant[F]
trait Invariant[F[_]]
object Invariant:
given ContravariantMonoidal[Foo] = ???
given ContravariantMonoidal[Bar] = ???

trait Contravariant[F[_]] extends Invariant[F]
object Contravariant:
trait Ops[F[_], A]:
def contramap[B](f: B => A): F[B] = ???

object catsSyntax:
implicit def toContravariantOps[F[_]: Contravariant, A](target: F[A]): Contravariant.Ops[F, A] = ???

object odinSyntax:
implicit class LoggerSyntax[F[_]](logger: Logger[F]):
def contramap(f: String => String): Logger[F] = ???

import catsSyntax._
import odinSyntax.LoggerSyntax

class Test:
def fails = new WriterTLogger[Option].contramap(identity)
def works = LoggerSyntax(new WriterTLogger[Option]).contramap(identity)

21 changes: 21 additions & 0 deletions tests/pos/i18163.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import scala.language.implicitConversions

trait Foo[A]
trait Bar[B]
trait Qux[C]
class Log[K[_]]

trait Inv[F[_]]
object Inv:
given monFoo: Inv[Foo] = ???
given monBar: Inv[Bar] = ???

trait InvOps[H[_], D] { def desc(s: String): H[D] = ??? }
trait LogOps[L[_]] { def desc(s: String): Log[L] = ??? }

class Test:
implicit def LogOps[Q[_]](l: Log[Q]): LogOps[Q] = ???
implicit def InvOps[J[_], E](j11: J[E])(implicit z: Inv[J]): InvOps[J, E] = ???

def fails = new Log[Qux].desc("fails")
def works = LogOps[Qux](new Log[Qux]).desc("works")
Loading