Skip to content

overriding val prevents trait parameter check #9460

@bishabosha

Description

@bishabosha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions