Skip to content

Fix #2198: Don't widen module singletons #2206

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
Apr 10, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 9, 2017

Since module classes are a compiler-generated construct that's not directly
visible to programmers, it seems better not to automatically widen a module
singleton to its underlying class.

Fixes #2198.

Since module classes are a compiler-generated construct that's not directly
visible to programmers, it seems better not to automatically widen a module
singleton to its underlying class.

Fixes scala#2198.
@odersky odersky requested a review from liufengyun April 9, 2017 15:02
@liufengyun
Copy link
Contributor

Looks good to me, but what about case val which are not modules defined by enums?

@smarter
Copy link
Member

smarter commented Apr 9, 2017

LGTM also, you should be able to revert the code change in #1448 but keep the test and it should still work.

@odersky
Copy link
Contributor Author

odersky commented Apr 10, 2017

I'd leave #1448 in. It's still a useful subtyping relationship to have.

@odersky
Copy link
Contributor Author

odersky commented Apr 10, 2017

@liufengyun Good question about enum vals. Here's what, e.g. None translates to:

final case val None: Option[Nothing] = 
  {
    final class $anon() extends Option[Nothing]() { 
      def isDefined: Boolean = false
      def enumTag: Int = 1
      override def toString: String = "None"
    }
    new Option[Nothing]{...}(): Option[Nothing]
  }

I think there's nothing to do. None is an Option[Nothing], and should be widened to that. This is analogous to the change in enum classes where apply also returns instances of the enum class itself instead of soemthing more specific.

@odersky odersky merged commit 80f9b6d into scala:master Apr 10, 2017
@allanrenucci allanrenucci deleted the fix-#2198 branch December 14, 2017 19:18
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.

3 participants