Skip to content
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

Cannot override a val from the parent class #2051

Closed
LPTK opened this issue Mar 5, 2017 · 1 comment · Fixed by #2096
Closed

Cannot override a val from the parent class #2051

LPTK opened this issue Mar 5, 2017 · 1 comment · Fixed by #2096

Comments

@LPTK
Copy link
Contributor

LPTK commented Mar 5, 2017

This works in Scalac, but not in Dotty:

class A[T](val x:T)
class B[T](override val x:T) extends A[T](x)

Dotty complains:

Welcome to Scala.next (pre-alpha, git-hash: 06d3f7a)  (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_65).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class A[T](val x:T)
defined class A
scala> class B[T](override val x:T) extends A[T](x)
-- Error: <console> ------------------------------------------------------------
5 |class B[T](override val x:T) extends A[T](x)
  |                        ^
  |                        overriding value x in class A of type T;
  |                         method x of type => T has incompatible type

Removing the override val keywords in B makes it compile, but it's not always possible (e.g. for case classes).

@DarkDimius
Copy link
Contributor

Refchecks is to blame. should be easy to fix.

@liufengyun liufengyun self-assigned this Mar 14, 2017
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2017
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2017
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2017
DarkDimius added a commit that referenced this issue Mar 15, 2017
Fix #2051: allow override T with => T or ()T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants