Skip to content

Allow abstract type members in objects. #2044

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 3, 2017

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@DarkDimius
Copy link
Contributor

why?

@nicolasstucki
Copy link
Contributor Author

Because scalac allows it.

Furthermore it is already possible to have abstract types in objects by defining it in a trait

trait A {
 type T <: Any
}

object B extends A // B has the abstract type T

In this case it would be simpler to define it as

object B {
  type T  <: Any
}

@odersky
Copy link
Contributor

odersky commented Mar 2, 2017

Do we have a test that checks that bounds of abstract type members are non-empty, i.e. lower bound <: upper bound? In that case, LGTM

@@ -27,7 +27,8 @@ object Tiark4 {
v.brand("boom!")
}
object V { // error: cannot be instantiated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error of the bound >: Any <: Nothing is the reason for the cannot be instantiated error, the full message is quite clear on the source of the issue.

@odersky odersky merged commit 917a7ed into scala:master Mar 3, 2017
@sjrd
Copy link
Member

sjrd commented Mar 6, 2017

See here for a concrete use case: https://github.com/sjrd/scala-unboxed-option/blob/4222ec1d95982ac7a5912c1d06eacb8f7b09554f/src/main/scala/uoption/package.scala#L23
Also in this case it's even in a package object

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.

4 participants