diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 571d90181d18..88576ede9eda 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3483,28 +3483,41 @@ class Typer extends Namer } // try an extension method in scope - pt match { + pt match case selProto @ SelectionProto(selName: TermName, mbrType, _, _) => + val origCtx = ctx def tryExtension(using Context): Tree = + var tried: untpd.Tree = untpd.EmptyTree try findRef(selName, WildcardType, ExtensionMethod, tree.srcPos) match case ref: TermRef => - extMethodApply(untpd.ref(ref).withSpan(tree.span), tree, mbrType) + tried = untpd.ref(ref).withSpan(tree.span) + extMethodApply(tried, tree, mbrType) case _ => findRef(selProto.extensionName, WildcardType, ExtensionMethod, tree.srcPos) match case ref: TermRef => - extMethodApply(untpd.ref(ref).withSpan(tree.span), tree, mbrType) + tried = untpd.ref(ref).withSpan(tree.span) + extMethodApply(tried, tree, mbrType) case _ => EmptyTree - catch case ex: TypeError => errorTree(tree, ex, tree.srcPos) + catch case ex: TypeError => + ex match + case ex: CyclicReference if ex.denot.is(Extension) && ex.denot.name == selName => + report.error( + em"""An extension method for `.$selName` was tried but could not be fully constructed + |since there was a cyclic reference involving ${ex.denot.symbol.showLocated}""", + tree.srcPos)(using origCtx) + case _ => + if tried.isEmpty then EmptyTree + else errorTree(tried, ex, tree.srcPos) + val nestedCtx = ctx.fresh.setNewTyperState() - val app = tryExtension(using nestedCtx) - if (!app.isEmpty && !nestedCtx.reporter.hasErrors) { + val tried = tryExtension(using nestedCtx) + if !tried.isEmpty && !nestedCtx.reporter.hasErrors then nestedCtx.typerState.commit() - return ExtMethodApply(app) - } - else if !app.isEmpty then - rememberSearchFailure(tree, SearchFailure(app.withType(FailedExtension(app, pt)))) + return ExtMethodApply(tried) + else if !tried.isEmpty then + rememberSearchFailure(tree, + SearchFailure(tried.withType(FailedExtension(tried, pt)))) case _ => - } // try an implicit conversion val prevConstraint = ctx.typerState.constraint diff --git a/scala3doc/src/dotty/dokka/tasty/BasicSupport.scala b/scala3doc/src/dotty/dokka/tasty/BasicSupport.scala index e49244678e44..08b1cfa2ee66 100644 --- a/scala3doc/src/dotty/dokka/tasty/BasicSupport.scala +++ b/scala3doc/src/dotty/dokka/tasty/BasicSupport.scala @@ -5,6 +5,7 @@ import org.jetbrains.dokka.model._ import collection.JavaConverters._ import dotty.dokka._ import dotty.dokka.model.api.Annotation +import doc.DocumentationNode import dotty.dokka.model.api.TastyDocumentableSource trait BasicSupport: @@ -34,10 +35,11 @@ trait BasicSupport: extension (sym: Symbol): - def documentation(using cxt: Context) = sym.documentation match - case Some(comment) => + def documentation(using cxt: Context): Map[SourceSetWrapper, DocumentationNode] = + qctx.reflect.SymbolMethods.documentation(sym) match + case Some(comment) => Map(sourceSet -> parseComment(comment, sym.tree)) - case None => + case None => Map.empty def source(using ctx: Context) = diff --git a/tests/neg/i7986.check b/tests/neg/i7986.check new file mode 100644 index 000000000000..042182324634 --- /dev/null +++ b/tests/neg/i7986.check @@ -0,0 +1,5 @@ +-- Error: tests/neg/i7986.scala:3:56 ----------------------------------------------------------------------------------- +3 |extension (project: Project) def dependencies = project.name.dependencies // error, following a cyclic reference warning + | ^^^^^^^^^^^^ + | An extension method for `.dependencies` was tried but could not be fully constructed + | since there was a cyclic reference involving method dependencies diff --git a/tests/neg/i7986.scala b/tests/neg/i7986.scala new file mode 100644 index 000000000000..61c896c4e145 --- /dev/null +++ b/tests/neg/i7986.scala @@ -0,0 +1,3 @@ +case class Project(name: String) +extension (name: String) def dependencies = ??? +extension (project: Project) def dependencies = project.name.dependencies // error, following a cyclic reference warning \ No newline at end of file diff --git a/tests/pos/i7986.scala b/tests/pos/i7986.scala new file mode 100644 index 000000000000..335ff51f5649 --- /dev/null +++ b/tests/pos/i7986.scala @@ -0,0 +1,3 @@ +case class Project(name: String) +extension (name: String) def dependencies: String = ??? +extension (project: Project) def dependencies: String = project.name.dependencies diff --git a/tests/pos/i8256.scala b/tests/pos/i8256.scala index ecccc21c639b..bb084cc373d8 100644 --- a/tests/pos/i8256.scala +++ b/tests/pos/i8256.scala @@ -7,4 +7,4 @@ val a = 1 val fetch = implicitly[Test[1]] -@main def main() : Unit = {} \ No newline at end of file +@main def test() : Unit = {} \ No newline at end of file