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

Error message improvement for illegal access extension methods #14730

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ object ErrorReporting {
i""".
|Extension methods were tried, but the search failed with:
|
| ${nested.head.explanation}"""
|${nested.head.explanation.indented(4)}"""
else if tree.hasAttachment(desugar.MultiLineInfix) then
i""".
|Note that `${tree.name}` is treated as an infix operator in Scala 3.
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,9 @@ trait Implicits:
ctx.reporter.removeBufferedMessages
adapted.tpe match {
case _: SearchFailureType => SearchFailure(adapted)
case _ =>
case error: PreviousErrorType if !adapted.symbol.isAccessibleFrom(cand.ref.prefix) =>
SearchFailure(adapted.withType(new NestedFailure(error.msg, pt)))
case _ =>
// Special case for `$conforms` and `<:<.refl`. Showing them to the users brings
// no value, so we instead report a `NoMatchingImplicitsFailure`
if (adapted.symbol == defn.Predef_conforms || adapted.symbol == defn.SubType_refl)
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i12573.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- [E008] Not Found Error: tests/neg/i12573.scala:23:38 ----------------------------------------------------------------
23 |val w: Value[8] = DFBits(Value[8](8)).getDFType.width // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| value getDFType is not a member of DFBits[(8 : Int)].
| Extension methods were tried, but the search failed with:
|
| method getDFType cannot be accessed as a member of DFType.type from module class i12573$package$.
| Access to protected method getDFType not permitted because enclosing package object i12573$package
| is not a subclass of object DFType where target is defined
23 changes: 23 additions & 0 deletions tests/neg/i12573.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Value[T <: Int](val value: T)

sealed trait DFType:
type Width <: Int
val width: Value[Width]

object DFType:
trait TC[T]:
type Type <: DFType
def apply(t: T): Type
type Aux[T, Type0 <: DFType] = TC[T] { type Type = Type0 }
transparent inline given ofDFType[T <: DFType]: TC[T] =
new TC[T]:
type Type = T
def apply(t: T): Type = t

extension [T, Type <: DFType](t: T)(using tc: Aux[T, Type])
protected def getDFType: Type = tc(t)

final case class DFBits[W <: Int](width: Value[W]) extends DFType:
type Width = W

val w: Value[8] = DFBits(Value[8](8)).getDFType.width // error