diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index 2f2f32fee995..b779df03bd95 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -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. diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index fc1fd57c7bd8..4fae9264939d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -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) diff --git a/tests/neg/i12573.check b/tests/neg/i12573.check new file mode 100644 index 000000000000..d250f4beabbe --- /dev/null +++ b/tests/neg/i12573.check @@ -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 \ No newline at end of file diff --git a/tests/neg/i12573.scala b/tests/neg/i12573.scala new file mode 100644 index 000000000000..c45ef6974a84 --- /dev/null +++ b/tests/neg/i12573.scala @@ -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 \ No newline at end of file