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

Let inlining report compiletime.error text #22561

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,13 @@ object Inlines:
inContext(evCtx) {
val evidence = evTyper.inferImplicitArg(tpe, callTypeArgs.head.span)
evidence.tpe match
case fail: Implicits.LateMismatchedImplicit =>
val addendum = fail.errors match
case Nil => ""
case errs => errs.map(_.msg).mkString("a search with errors:\n ", "\n ", "")
errorTree(call, evTyper.missingArgMsg(evidence, tpe, addendum))
case fail: Implicits.SearchFailureType =>
errorTree(call, evTyper.missingArgMsg(evidence, tpe, ""))
errorTree(call, evTyper.missingArgMsg(evidence, tpe, where = ""))
case _ =>
evidence
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@ object Implicits:
def msg(using Context): Message =
em"${errors.map(_.msg).mkString("\n")}"
}

class LateMismatchedImplicit(ref: TermRef,
expectedType: Type,
argument: Tree,
val errors: List[Diagnostic.Error]) extends MismatchedImplicit(ref, expectedType, argument)
end Implicits

import Implicits.*
Expand Down Expand Up @@ -1233,6 +1238,8 @@ trait Implicits:
NoMatchingImplicitsFailure
else if Splicer.inMacroExpansion && tpe <:< pt then
SearchFailure(adapted.withType(new MacroErrorsFailure(ctx.reporter.allErrors.reverse, pt, argument)))
else if ctx.isAfterTyper then
SearchFailure(adapted.withType(LateMismatchedImplicit(ref, pt, argument, ctx.reporter.allErrors.reverse)))
else
SearchFailure(adapted.withType(new MismatchedImplicit(ref, pt, argument)))
}
Expand Down
32 changes: 32 additions & 0 deletions tests/neg/i15788.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Error: tests/neg/i15788.scala:39:13 ---------------------------------------------------------------------------------
39 | fff1[Test2] // error
| ^
| Field 'a' not found
-- Error: tests/neg/i15788.scala:42:15 ---------------------------------------------------------------------------------
42 | summonInline[Test[Test2]].test // error
| ^
| Field 'a' not found
-- [E172] Type Error: tests/neg/i15788.scala:45:6 ----------------------------------------------------------------------
45 | fff2[Test2] // error
| ^^^^^^^^^^^
| No given instance of type Test[Test2] was found for a search with errors:
| Field 'a' not found.
| I found:
|
| Test.given_Test_A[Test2](
| Test2.$asInstanceOf[
| scala.deriving.Mirror.Product{
| type MirroredMonoType = Test2; type MirroredType = Test2; type MirroredLabel = ("Test2" : String);
| type MirroredElemTypes = (String, Int); type MirroredElemLabels = (("q" : String), ("w" : String))
| }
| ]
| )
|
| But given instance given_Test_A in object Test does not match type Test[Test2].
|--------------------------------------------------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from i15788.scala:35
35 | summonInline[Test[P]].test
| ^^^^^^^^^^^^^^^^^^^^^
--------------------------------------------------------------------------------------------------------------------
46 changes: 46 additions & 0 deletions tests/neg/i15788.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import scala.deriving.Mirror
import scala.compiletime.*

trait Test[A] {
def test: String
}

object Test {

inline def findA[T <: Tuple]: Unit =
inline erasedValue[T] match {
case _: EmptyTuple => error("Field 'a' not found")
case _: ("a" *: tl) => ()
case _: (_ *: tl) => findA[tl]
}

inline given [A <: Product] => (mm: Mirror.ProductOf[A]) => Test[A] = new {
override def test: String = {
findA[mm.MirroredElemLabels]
"test"
}
}
}

final case class Test1(a: String, b: Int)
final case class Test2(q: String, w: Int)

object Main {
inline def fff1[P <: Product](using ggg: Test[P]): String = {
ggg.test
}

inline def fff2[P <: Product]: String = {
summonInline[Test[P]].test
}

fff1[Test1]
fff1[Test2] // error

summonInline[Test[Test1]].test
summonInline[Test[Test2]].test // error

fff2[Test1]
fff2[Test2] // error
}
Loading