Skip to content

Nothing inferred when class type parameter is missing #3434

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

Closed
allanrenucci opened this issue Nov 3, 2017 · 4 comments
Closed

Nothing inferred when class type parameter is missing #3434

allanrenucci opened this issue Nov 3, 2017 · 4 comments

Comments

@allanrenucci
Copy link
Contributor

class A[T]
class B extends A
> dotc Test.scala -Xprint:frontend
result of Test.scala after frontend:

package <empty> {
  class A[T]() extends Object() { 
    T
  }
  class B() extends A[Nothing]() {}
}

Both dotty and scalac infer B extends A[Nothing]. Should we require the type parameter to be specified? Or at least emit a warning?

@smarter
Copy link
Member

smarter commented Nov 3, 2017

I don't think we should require the type parameter to be specified since in general we do want it to be inferrable, e.g.:

class A[T](x: T)
class B extends A(1)

Though I guess we could refuse to infer Nothing for class type parameters by default and force the user to write it explicitly.

@allanrenucci
Copy link
Contributor Author

Are there cases where inferred Nothing or Any are not code smell?

@edmundnoble
Copy link
Contributor

Inferred Nothing is fine for implicits, in a lot of cases it's necessary (for example, see https://github.com/milessabin/shapeless/blob/wip/smc/core/src/main/scala/shapeless/smc.scala#L305) but I don't think it makes sense for extends to even have type inference here.

@nicolasstucki nicolasstucki changed the title Nothing inferred when type parameter is missing Nothing inferred when class type parameter is missing Nov 12, 2017
@odersky
Copy link
Contributor

odersky commented Jan 2, 2018

I am reluctant to change it, as it might have valid uses, and the change would introduce an irregularity.

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

4 participants