Skip to content

Prevent mismatches on members named md #2526

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
merged 2 commits into from
May 30, 2017
Merged

Conversation

Varunram
Copy link
Contributor

Intended as a fix for #1944. Tests are failing because of an AssertionError which, after hours of desperation, I can't seem to find out. Please do suggest where the error might be. Many thanks to @felixmulder for helping me out with however basic my questions may be. Thanks for your time and patience Felix!

if (url.endsWith(".md")) node.setUrl {
val x = new java.net.URI(url.toString)
val path = x.getPath()
val method = path.substring(path.lastIndexOf('/')+1).dropRight(3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic here is the tricky bit. You have two alternatives:

  1. You're linking from to a class or some other kind that exists in source: [md](my.package.md)
  2. You're linking some other file that is not a class/object: [md](../path/to/my/file.md) or [md](http://path.to/file.md)

You want to make sure that both of these are legal. As it stands now - the check below is a bit too simple, one reason being: I don't have / in (99.9% of) my URIs to classes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to consider - since you now have ctx you could do

ctx.error(s"""Ambiguous reference to "$url"""", pos)

to show the user the ambiguity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger!

(new NodeVisitor(
new VisitHandler(classOf[Link], new Visitor[Link] with MemberLookup {
override def visit(node: Link): Unit = {
val url = node.getUrl
if (url.endsWith(".md")) node.setUrl {
val x = new java.net.URI(url.toString)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this variable name, you can do better thanx :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah Sorry. I would process this with the other changes :)

val path = x.getPath()
val method = path.substring(path.lastIndexOf('/')+1).dropRight(3);
val method1 = method.toTypeName
if ((url.endsWith(".md")) && (ctx.getClassIfDefined(method1).exists == false)) node.setUrl{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.getClassIfDefined(method1).exists == false is the same as: !ctx.getClassIfDefined(method1).exists. Please use the latter :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, that was more out of despair that by some unearthly force, it would work. Sadly it didn't :/

@felixmulder
Copy link
Contributor

Could you post a gist of the stacktrace from the assertion?

@Varunram
Copy link
Contributor Author

@felixmulder Yeah sure, sorry for the late reply but here goes: I have no idea why the tests on CI passed though...

[doc info] Generating doc page for: dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler$.TempPolyType$
exception caught when loading module class <empty>: java.lang.AssertionError: assertion failed: denotation module class <root> invalid in run 1. ValidFor: Period(1..7, run = 2)
Exception in thread "main" java.lang.AssertionError: assertion failed: denotation module class <root> invalid in run 1. ValidFor: Period(1..7, run = 2)
	at scala.Predef$.assert(Predef.scala:170)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:726)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:782)
	at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:405)
	at dotty.tools.dotc.core.Symbols$.toDenot(Symbols.scala:615)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.companionNamed(SymDenotations.scala:943)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.scalacLinkedClass(SymDenotations.scala:928)
	at dotty.tools.dotc.core.SymbolLoader.complete(SymbolLoaders.scala:286)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:219)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:197)
	at dotty.tools.dotc.core.Denotations$DenotationsBase$class.select$1(Denotations.scala:1193)
	at dotty.tools.dotc.core.Denotations$DenotationsBase$class.recurSimple$1(Denotations.scala:1221)
	at dotty.tools.dotc.core.Denotations$DenotationsBase$class.recur$1(Denotations.scala:1223)
	at dotty.tools.dotc.core.Denotations$DenotationsBase$class.staticRef(Denotations.scala:1225)
	at dotty.tools.dotc.core.Contexts$ContextBase.staticRef(Contexts.scala:541)
	at dotty.tools.dotc.core.Symbols$class.getClassIfDefined(Symbols.scala:372)
	at dotty.tools.dotc.core.Contexts$Context.getClassIfDefined(Contexts.scala:57)
	at dotty.tools.dottydoc.staticsite.MarkdownLinkVisitor$$anon$1.visit(MarkdownLinkVisitor.scala:24)
	at dotty.tools.dottydoc.staticsite.MarkdownLinkVisitor$$anon$1.visit(MarkdownLinkVisitor.scala:17)
	at com.vladsch.flexmark.ast.VisitHandler.visit(VisitHandler.java:11)
	at com.vladsch.flexmark.ast.NodeVisitor.visit(NodeVisitor.java:38)
	at com.vladsch.flexmark.ast.NodeVisitor.visitChildren(NodeVisitor.java:30)
	at com.vladsch.flexmark.ast.NodeVisitor.visit(NodeVisitor.java:40)
	at com.vladsch.flexmark.ast.NodeVisitor.visitChildren(NodeVisitor.java:30)
	at com.vladsch.flexmark.ast.NodeVisitor.visit(NodeVisitor.java:40)
	at com.vladsch.flexmark.ast.NodeVisitor.visitChildren(NodeVisitor.java:30)
	at com.vladsch.flexmark.ast.NodeVisitor.visit(NodeVisitor.java:40)
	at com.vladsch.flexmark.ast.NodeVisitor.visitChildren(NodeVisitor.java:30)
	at com.vladsch.flexmark.ast.NodeVisitor.visit(NodeVisitor.java:40)
	at dotty.tools.dottydoc.staticsite.MarkdownLinkVisitor$.apply(MarkdownLinkVisitor.scala:48)
	at dotty.tools.dottydoc.staticsite.MarkdownPage$$anonfun$initFields$2.apply(Page.scala:169)
	at dotty.tools.dottydoc.staticsite.MarkdownPage$$anonfun$initFields$2.apply(Page.scala:166)
	at scala.Option.map(Option.scala:146)
	at dotty.tools.dottydoc.staticsite.MarkdownPage.initFields(Page.scala:166)
	at dotty.tools.dottydoc.staticsite.Page$class.yaml(Page.scala:41)
	at dotty.tools.dottydoc.staticsite.MarkdownPage.yaml(Page.scala:156)
	at dotty.tools.dottydoc.staticsite.Site.render(Site.scala:423)
	at dotty.tools.dottydoc.staticsite.Site$$anonfun$generateHtmlFiles$1$$anonfun$apply$mcV$sp$6.apply(Site.scala:244)
	at dotty.tools.dottydoc.staticsite.Site$$anonfun$generateHtmlFiles$1$$anonfun$apply$mcV$sp$6.apply(Site.scala:236)
	at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
	at dotty.tools.dottydoc.staticsite.Site$$anonfun$generateHtmlFiles$1.apply$mcV$sp(Site.scala:236)
	at dotty.tools.dottydoc.staticsite.Site.createOutput(Site.scala:187)
	at dotty.tools.dottydoc.staticsite.Site.generateHtmlFiles(Site.scala:235)
	at dotty.tools.dottydoc.DocDriver.main(DocDriver.scala:57)
	at dotty.tools.dottydoc.Main.main(Main.scala)

@Varunram
Copy link
Contributor Author

Varunram commented May 24, 2017

The rest of the stack is pretty normal, just usual stuff like generating [doc]info. Must add that there were no external warning associated, just the standard two ones at the start before compilation

Copy link
Contributor

@felixmulder felixmulder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpicks, then LGTM! 🎉

url.subSequence(0, url.lastIndexOf('.')).append(".html")

if (url.endsWith(".md")) {
if (url.subSequence(0, url.lastIndexOf('.')).indexOf("/") <0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after <

if (url.endsWith(".md")) {
if (url.subSequence(0, url.lastIndexOf('.')).indexOf("/") <0) {
val method = url.subSequence(0, url.lastIndexOf('.')).toString.toTypeName
if (ctx.getClassIfDefined(method).exists) node.setUrl{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after node.setUrl

} else {
ctx.error(s"""Ambiguous reference to "$url"""")
}
} else node.setUrl{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after node.setUrl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for being late! Didn't catch your comment amongst all the action going on here :)

@felixmulder felixmulder merged commit 2127e9f into scala:master May 30, 2017
@felixmulder
Copy link
Contributor

Thanks!

@felixmulder
Copy link
Contributor

Merging this broke genDocs, will revert

felixmulder added a commit to dotty-staging/dotty that referenced this pull request May 30, 2017
felixmulder added a commit that referenced this pull request May 30, 2017
Revert "Prevent mismatches on members named md (#2526)"
@Varunram
Copy link
Contributor Author

Um. I don't know why the tests passed. It has a java:lang exception error still :/

@felixmulder
Copy link
Contributor

It doesn't run genDocs in the CI, but maybe it should.

@Varunram
Copy link
Contributor Author

Still, I can't seem to figure out what's causing the exception. Any ideas?

@felixmulder
Copy link
Contributor

The exception suggests that something is touched outside of its allowed run. I'm sorry, right now we're in crunch mode, I'll get back to this tomorrow or the day after.

@Varunram
Copy link
Contributor Author

No problem at all. I'm the one who should be sorry for causing the extra trouble. Really sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants