Skip to content
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

available spec is silent on the fact that the implicit scope of a.A includes package object a #4427

Closed
scabug opened this issue Mar 31, 2011 · 11 comments

Comments

@scabug
Copy link

scabug commented Mar 31, 2011

object Main {
  new qwe.C1(): String
}

package qwe {
  class C1
}

package object qwe {
  implicit def c1ToString(ref: C1): String = ""
}

=== Additional information ===

A straw poll reveals that Scala programmers far and wide have come to rely on the implicit scope including the package objects of the containing packages of the parts of the type.

Assuming this is intentional, or at least serendipitous, it ought to be enshrined in the spec.

Related: http://youtrack.jetbrains.net/issue/SCL-2996

=== What versions of the following are you using? ===

  • Scala: 2.9.0.RC1
@scabug
Copy link
Author

scabug commented Mar 31, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4427?orig=1
Reporter: @retronym

@scabug
Copy link
Author

scabug commented Mar 18, 2012

@odersky said:
It is enshrined in the spec. See the following definition in the SLS. The last two clauses explain the behavior.

The {\em implicit scope} of a type $T$ consists of all companion modules
(\sref{sec:object-defs}) of classes and package objects (\sref{sec:pkg-obj})
of packages that are associated with the
implicit parameter's type. Here, we say a class $C$ is {\em
associated} with a type $T$, if it is a base class
(\sref{sec:linearization}) of some part of $T$. A package $p$ is
associated with a type $T$ if its type is a part of $T$.
The {\em parts} of a
type $T$ are:
\begin{itemize}
\item
if $T$ is a compound type ~\lstinline@$T_1$ with $\ldots$ with $T_n$@, the
union of the parts of $T_1 \commadots T_n$, as well as $T$ itself,
\item
if $T$ is a parameterized type ~\lstinline@$S$[$T_1 \commadots T_n$]@,
the union of the parts of $S$ and $T_1 \commadots T_n$,
\item
if $T$ is a singleton type ~\lstinline@$p$.type@, the parts of the type
of $p$,
\item
if $T$ is a type projection ~\lstinline@$S$#$U$@, the parts of $S$ as
well as $T$ itself,
\item
in all other cases, just $T$ itself.
\end{itemize}

@scabug
Copy link
Author

scabug commented Mar 18, 2012

@retronym said (edited on Mar 18, 2012 10:51:32 PM UTC):
I was looking http://www.scala-lang.org/docu/files/ScalaReference.pdf, which still says: "The implicit scope of a type T consists of all companion modules (§5.4) of classes that are associated with the implicit parameter’s type". Glad to see the wording has been expanded. Where is the official source for the spec these days? (scala/scala-dist on GitHub seems not to be the one...)

@scabug
Copy link
Author

scabug commented Aug 13, 2012

Martin Kneissl (mkneissl) said:
The Specification as downloadable from scala-lang.org is still as incomplete as described by Jason's comment. Any updates on this issue?

@scabug
Copy link
Author

scabug commented May 22, 2013

Régis Jean-Gilles (rjean-gilles) said:
I second that. The spec at scala-lang.org is still the same old version. It is very unfortunate that the primary reference is not up to date. This is a source of confusion and head scratching. Could it please be updated? And where can we even have a look at the up to date version? Thanks in advance.

@scabug
Copy link
Author

scabug commented Jun 27, 2013

@Blaisorblade said:
Since the available spec is not up-to-date, I'm reopening this.

@scabug
Copy link
Author

scabug commented Dec 26, 2013

@paulp said:
...and now nearly three years after this ticket was opened, it's still not in the "specification" (though I don't know why this term is used to describe the document in question.)

@scabug
Copy link
Author

scabug commented Aug 4, 2014

Shiva Wu (shivawu) said:
More than 3 years, still not documented.

@scabug
Copy link
Author

scabug commented Aug 4, 2014

@som-snytt said (edited by @Blaisorblade on Aug 7, 2014 10:33:40 AM UTC):
This seems to be the current language:

http://www.scala-lang.org/files/archive/spec/2.11/07-implicit-parameters-and-views.html

Note that packages are internally represented as classes with companion modules to hold the package members. Thus, implicits defined in a package object are part of the implicit scope of a type prefixed by that package.

@scabug
Copy link
Author

scabug commented Aug 4, 2014

@Blaisorblade said:
IMHO, at this point it's just a matter of somebody merging the posted text and sending a PR. Here's my try:

scala/scala#3915

Note that packages are internally represented as classes with companion modules to hold the package members. Thus, implicits defined in a package object are part of the implicit scope of a type prefixed by that package.

Unless that's documented, that does not count even as correct, and even less as clear. Quoting from https://github.com/scala/scala/tree/2.11.x/spec:

First of all, the language specification is meant to be correct, precise and clear.

@scabug
Copy link
Author

scabug commented Aug 7, 2014

@Blaisorblade said:
I had completely misunderstood Marki's comment. After he clarified it on Github (scala/scala#3915 (comment)), I added the quote tag which I'd have required there to get it (sorry, I'm slightly limited).

So, it seems that the spec is in fact already correct on this point (since a while), and the question is just how to best explain it (which is extremely important, but does not deserve such an open ticket). If everybody involved agrees, we can close the ticket.

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

No branches or pull requests

2 participants