Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Dec 12, 2016

Review by @felixmulder ?

@sjrd
Copy link
Member

sjrd commented Dec 12, 2016

To exercise this in bootstrap, you could remove all the : Position I had to add in JSCodeGen on local implicit val pos'es, for example this one: https://github.com/lampepfl/dotty/blob/master/compiler/sjs/backend/sjs/JSCodeGen.scala#L130

Drop explicit types for local implicit vals of type Context
and Position. Exercises the functionality and shortens the code.
@odersky
Copy link
Contributor Author

odersky commented Dec 12, 2016

To exercise this in bootstrap, you could remove all the : Position I had to add in JSCodeGen on local implicit val pos'es, for example this one:

@sjrd Done. I saw there were quite a few of those.

/** Map this function over given type */
def mapOver(tp: Type): Type = {
implicit val ctx: Context = this.ctx // Dotty deviation: implicits need explicit type
implicit val ctx = this.ctx // Dotty deviation: implicits need explicit type
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the comment is obsolete :P

}
else {
implicit val ctx: Context = (new ContextBase).initialCtx // Dotty deviation: implicits need explicit type
implicit val ctx = (new ContextBase).initialCtx // Dotty deviation: implicits need explicit type
Copy link
Member

Choose a reason for hiding this comment

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

Another obsolete comment.

Since we now allow to drop the explicit type of a local implicit val
it can happen that this causes a cyclic reference, namely when the
typechecking of the right-hand side involves an implicit search.
It's unpractical and fragile to avoid this. Instead we give now
a nice error message explaining the problem and how to fix it in
source code.
Needed an // error annotation
errorMsg(ex.show, ctx)

if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm)
em"""cyclic reference involving implicit $cycleSym
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@felixmulder Line 2 and 3 of this message might be moved to an explanation. But we can also leave it like this, I think.

@felixmulder
Copy link
Contributor

@sjrd @odersky: note that the JSCodeGen.scala is not part of the sources being compiled in tests.

The sources for the Scala.JS IR were added as a source dependency (by sbt) and compiled by sbt with dotty compiler. The resulting class files were previously erroneously put on the classpath during bootstrap.

Therefore the Scala.JS backend is no longer compiled with the tests. Ask me today and I'll give a more thorough explanation in person.

@felixmulder
Copy link
Contributor

LGTM. Added a proper error message as per @odersky's recommendation.

@odersky
Copy link
Contributor Author

odersky commented Dec 15, 2016

@felixmulder I decided to revert the last commit. I think moving the explanation away into a separate step is counter-productive here because the error message alone is too opaque to tell you anything. So I think in this case it's actually better to give the explanation as part of the error message.

@felixmulder
Copy link
Contributor

@odersky - that's fine by me 👍

@smarter
Copy link
Member

smarter commented Dec 15, 2016

Ping @olafurpg since this affect scalafix

@olafurpg
Copy link
Contributor

Thanks for the ping @smarter. I will update the ExplicitImplicit rewrite to allow optional type annotations for local implicit vals. To be sure I understand correctly, a val is considered local if and only if it's not defined inside a template?

class/trait/object A {
  // not OK
  implicit val x =???
  def/val/var foo = {
    // OK
   implicit val x = ???
  }
}

@odersky
Copy link
Contributor Author

odersky commented Dec 15, 2016 via email

@odersky odersky merged commit a5620ab into scala:master Dec 15, 2016
@allanrenucci allanrenucci deleted the fix-#1784 branch December 14, 2017 16:59
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.

6 participants