Skip to content

overriding val prevents trait parameter check #9460

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
bishabosha opened this issue Jul 29, 2020 · 1 comment · Fixed by #12952
Closed

overriding val prevents trait parameter check #9460

bishabosha opened this issue Jul 29, 2020 · 1 comment · Fixed by #12952

Comments

@bishabosha
Copy link
Member

Minimized code

found by @texasbruce in #640 (comment)

trait A(val s: String) { println(s) }
trait B extends A { override val s = "B" } // requires override val s
class C extends B
@main def Test = C()

Output

prints null

Expectation

this error appears if we remove the override

-- Error: example.scala:3:6 ----------------------------------------------------
3 |class C extends B
  |      ^
  |      parameterized trait A is indirectly implemented,
  |      needs to be implemented directly so that arguments can be passed
1 error found

Notes

we can still prevent compilation with the init checker:

-- Error: example.scala:2:33 ---------------------------------------------------
2 |trait B extends A { override val s = "B" } // requires override val s
  |                                 ^
  |             Access non-initialized field s. Calling trace:
  |              -> trait A(val s: String) { println(s) }	[ example.scala:1 ]
1 error found
@som-snytt
Copy link
Contributor

On the linked ticket, I suggest that it's a feature to not require an arg for a val trait param that is overridden and unused in initializer.

griggt added a commit to griggt/dotty that referenced this issue Jun 26, 2021
anatoliykmetyuk added a commit that referenced this issue Jul 6, 2021
BarkingBad pushed a commit to BarkingBad/dotty that referenced this issue Jul 23, 2021
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.

2 participants