Dotty: `MarkdownLinkVisitor` mismatch on member named `md`

Created on 6 Feb 2017  Â·  13Comments  Â·  Source: lampepfl/dotty

In MarkdownLinkVisitor.scala we do two things:

  1. Replace relative/path/to/markdown.md with relative/path/to/markdown.html
  2. Member lookup on [isEmpty](scala.collection.immutable.Seq.isEmpty)

The first one is simply caught with .endsWith(".md"), which means you cannot call a package member md.

doctool novice help wanted bug low

All 13 comments

@felixmulder What are your suggestions? Maybe read the whole string and do something?

Well, we need to be able to distinguish between links that are part of the site as markdown templates ending in .md (later transformed to HTML) and actual source code in a package like:

package blabla

object md {
}

Where the object will have the path blabla.md and as such if referred to in another markdown file with: [md](blabla.md); that link will be transformed to <a href="{{ site.baseurl}}/api/blabla/md.html">md</a> or something similar.

Thanks for clarifying. What I thought was maybe we could add a try catch loop with Reflection and see if there exists a package. Would this be the right approach?

You won't know via reflection, as there is no loading of the compiled sources into the classloaders. You could do:

ctx.getClassIfDefined(str).exists

To see if the class exists in the current compilation unit or on the classpath.

Thanks! I'll test it up front and put in a PR later today

Okay, so I worked on this and get the error required: dotty.tools.dotc.core.Names.PreName. What I did was I cut the last three characters off the URL (after using lastIndexOf obviously) and placed them in str. What am I doing wrong here?

Could you show me the code snippet? I'm not sure I follow.

          val url = node.getUrl
          if(url.endsWith(".md")) {
            val x = new URI(url.toString)
            val path = x.getPath()
            val meth = path.substring(path.lastIndexOf('/')+1).dropRight(3);
            implicit ctx: Context => ctx.getClassIfDefined(meth).exists

I think I'm not handling the last line properly. Earlier I just had an _ but that doesn't do anything, so I thought I'd replace it with meth.isExists

well the last line produces a function from Context => Boolean, where the Context is marked implicit, but the function is not applied.

The function which contains this code should take a second parameter list (implicit ctx: Context)

The error statement : Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to dotty.tools.dotc.core.Names$PreName. Why can't I cast to Name.preName?

you should do meth.toTypeName, strings aren't names :)

Thanks for the heads up! But if I'm not wrong, String doesn't have toTypeName right? Names had toTypeName, so I'd be casting String to dotc.core.Name.PreName with toInstanceOf, but toTypeName? And thanks a ton for bearing up with all these noobish questions, really appreciate your help and time!

There are decorators for adding these methods. Have a look in other files
where ".toTypeName is used :)

On Tue, May 23, 2017, 15:59 Varunram Ganesh notifications@github.com
wrote:

Thanks for the heads up! But if I'm not wrong, String doesn't have
toTypeName right? Names had toTypeName, so I'd be casting String to
dotc.core.Name.PreName with toInstanceOf, buttoTypeName`? And thanks a
ton for bearing up with all these noobish questions, really appreciate your
help and time!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/lampepfl/dotty/issues/1944#issuecomment-303406963,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABdYwUajW-GQ3C2hPFNRslKT0zEkA_Gmks5r8uZEgaJpZM4L32r4
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

noti0na1 picture noti0na1  Â·  3Comments

odersky picture odersky  Â·  3Comments

travisbrown picture travisbrown  Â·  3Comments

dwijnand picture dwijnand  Â·  3Comments

milessabin picture milessabin  Â·  3Comments