-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dottydoc: Show implicit modifier in implicit function types #4954
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
Merged
Duhemm
merged 3 commits into
scala:master
from
dotty-staging:fix/dottydoc-implicit-function-type
Nov 29, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dotty.tools | ||
package dottydoc | ||
|
||
import dotty.tools.dotc.util.SourceFile | ||
import dotty.tools.dottydoc.model._ | ||
import dotty.tools.dottydoc.model.internal._ | ||
import dotty.tools.dottydoc.model.references._ | ||
|
||
import org.junit.Test | ||
import org.junit.Assert.{assertTrue, fail} | ||
|
||
class TypeRenderingTestFromTasty extends TypeRenderingTest with CheckFromTasty | ||
class TypeRenderingTestFromSource extends TypeRenderingTest with CheckFromSource | ||
abstract class TypeRenderingTest extends DottyDocTest { | ||
@Test def renderImplicitFunctionType = { | ||
val source = new SourceFile( | ||
"ImplicitFunctionType.scala", | ||
""" | ||
|package scala | ||
| | ||
|trait Test { | ||
| def a: implicit Int => Int = ??? | ||
| def b(x: implicit Int => Int) = ??? | ||
| type c = implicit Int => Int | ||
|} | ||
""".stripMargin | ||
) | ||
|
||
def checkImplicitFunctionType(ref: Reference) = ref match { | ||
case FunctionReference(_, _, isImplicit) => | ||
assertTrue("Should be an implicit function type", isImplicit) | ||
case _ => | ||
fail("Unexpected: " + ref) | ||
} | ||
|
||
checkFromSource(source :: Nil) { case (_, packages) => | ||
packages("scala") match { | ||
case PackageImpl(_, _, _, List(trt: Trait), _, _, _, _) => | ||
val List(a: Def, b: Def, c: TypeAlias) = trt.members.sortBy(_.name) | ||
checkImplicitFunctionType(a.returnValue) | ||
b.paramLists.head.list.head match { | ||
case NamedReference("x", ref, _, _) => | ||
checkImplicitFunctionType(ref) | ||
case _ => | ||
fail("Unexpected: " + b.paramLists.head.list.head) | ||
} | ||
checkImplicitFunctionType(c.alias.get) | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an outsider: This PR mostly makes sense to me, but I'm not sure why
ReferenceShower
is removed here.Not that I'm attached to it — it seems pretty-printing won't insert necessary extra parentheses — seems we'd have gotten
A & B => C
from both(A & B) => C
andA & (B => C)
. But is this handled better by the new code? It seems harder to get right once you flatten everything into nested maps, asasJava
seems to do.For the record, PlainPrinter/RefinedPrinter start handling this correctly in #4072 (tho the basic infrastructure was in place): recursive calls must pass the current precedence and insert parentheses around nodes with a lower precedence than the current one.
But I wonder if DottyDoc should reimplement this logic instead of reusing
RefinedPrinter
, since each deviation will confuse users. The only different requirement seems thatRefinedPrinter
uses a pretty-printing library designed to insert line-breaks where needed, but flattening that toString
without extra line-breaks should be feasible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it because the functionality is actually implemented twice: in
ReferenceShower
andRenderReference
.Instead of generating a string from the reference, we keep it in "java form" and use the tag to actually render it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, but the precedence bug seems still an issue; I've confirmed it (tho without this PR) and opened #4966.