Skip to content

Always exclude package objects from the implicit scope #8458

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 1 commit into from
Mar 6, 2020

Conversation

smarter
Copy link
Member

@smarter smarter commented Mar 6, 2020

Unlike Scala 2, in Dotty when constructing the implicit scope for a type
pkgA.Foo, we do not include the main package object (pkgA.package).
We don't include the package objects we define for top-level definitions
either.

However, when constructing the implicit scope for a type defined in a
package object (e.g. pkgA.foo$package.Foo), we did including the
implicits defined in the enclosing package object. This is problematic
because at the source-level it's hard to distinguish which definitions
will be included in the package object. For example, in the testcase
included in this commit, summon[ToString[A.AB]] used to succeed
because both the type AB and the given alias for ToString[AB] ended
up wrapped in a package object, but the other summon calls failed
because classes and given instances are not wrapped in a package object.

To fix this inconsistency, we now always exclude package objects from
the implicit scope, even for types defined in the package object itself.
The companion object of classes and opaque types stays the preferred
place to put implicit definitions and is not affected by this change.

@smarter smarter requested a review from odersky March 6, 2020 14:54
@smarter smarter force-pushed the implicit-package-object branch 2 times, most recently from 674c3ba to e19d998 Compare March 6, 2020 15:00
Unlike Scala 2, in Dotty when constructing the implicit scope for a type
`pkgA.Foo`, we do not include the main package object (`pkgA.package`).
We don't include the package objects we define for top-level definitions
either.

However, when constructing the implicit scope for a type defined in a
package object (e.g. `pkgA.foo$package.Foo`), we did including the
implicits defined in the enclosing package object. This is problematic
because at the source-level it's hard to distinguish which definitions
will be included in the package object. For example, in the testcase
included in this commit, `summon[ToString[A.AB]]` used to succeed
because both the type `AB` and the given alias for `ToString[AB]` ended
up wrapped in a package object, but the other summon calls failed
because classes and given instances are not wrapped in a package object.

To fix this inconsistency, we now always exclude package objects from
the implicit scope, even for types defined in the package objects itself.
The companion object of classes and opaque types stays the preferred
place to put implicit definitions and is not affected by this change.
@smarter smarter force-pushed the implicit-package-object branch from e19d998 to 686a1e4 Compare March 6, 2020 15:33
@odersky odersky merged commit fa23429 into scala:master Mar 6, 2020
@odersky odersky deleted the implicit-package-object branch March 6, 2020 16:43
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