Skip to content

Fix #2220: Change handling of package objects and tweak hk type inference #2205

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 4 commits into from
Apr 9, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 9, 2017

No description provided.

odersky added 3 commits April 9, 2017 13:02
 1. Invalidate packageObj cache when entering a package object
 2. Prefer package object members over same-named package members
    unless we are in the scala package
 3. Exclude package objects from no-double-bindings checks, since
    package objects may now be visited before indexing them.
@odersky odersky requested a review from smarter April 9, 2017 13:20
*
* If this is the scala package or the package object exists but is currently completing,
* look in the package first, and if nothing is found there, look in the package object second.
* Otherwise, look in the package object first, and if nothing is found there, in
Copy link
Member

Choose a reason for hiding this comment

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

The spec says "The package object should not define a member with the same name as one of the top-level objects or classes defined in package p. If there is a name conflict, the behavior of the program is currently undefined.", we probably want to update that at some points with the rules here.

Copy link
Member

Choose a reason for hiding this comment

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

else compareLower(bounds(param2), tyconIsTypeRef = false)
}
isMatchingApply(tp1) ||
canConstrain(param2) && canInstantiate(param2) ||
Copy link
Member

Choose a reason for hiding this comment

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

I have an alternative fix for #2201 at #2204. Your fix looks like it might help in some other situations, but we would need a testcase for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just merged #2204. I don't have a separate test case for this change, but would argue that the fact that we missed the case before means we cannot exclude that we will miss it in the future. So better play it safe.

* complete it too early, we freeze its superclass Any, so that no members can
* be entered in it. As a consequence, there should be no entry in the scala package
* object that hides a class or object in the scala package of the same name, because
* the behavior would then be unintuitive for such members.
Copy link
Member

Choose a reason for hiding this comment

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

Would it possible to detect when a scala package object member hides a scala class/object and return an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure. It would be tricky since everything we do in the scala package is fraught with causing all sorts of initialization errors. Not sure it's worth it really, given that we never had a problem so far.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

LGTM, I've tagged this PR "needs spec" so that in the future we can easily find it if we want to update http://www.scala-lang.org/files/archive/spec/2.13/09-top-level-definitions.html#package-objects (I think we should try to tag all PRs that will require spec changes, otherwise it's too easy to forget about them)

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

Successfully merging this pull request may close these issues.

2 participants