If you don't need to expose varfrom the outside (which I assume you are not doing this), then adding an explicit return type fixes the problem:
def f[X]: MyTrait[X] = new MyTrait[X] {
var x: X = _
def someFunc: X = x
}
Without an explicit type, the compiler displays problematic "structural refinement", that is, the type of which is as follows: MyTrait[X] { var x: X }.
- var private - , - , , .
def f[X] = new MyTrait[X] {
private var x: X = _
def someFunc: X = x
}