You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As it is currently implemented, yes, this type is visible. It's also possible to explicitly call the constructor to get instances:
scala>enumOption[+T] {
|caseSome(x: T)
|caseNone| }
// defined class Option
scala>newOption.Some(1)
valres0:Option.Some[Int] =Some(1)
But you only get a class (and a type) for cases with fields. Cases without fields become vals:
scala>newOption.None1|newOption.None|^^^^^^^^^^^|type`None` is not a member of Option- did you mean `Option.None`?
scala>typenope=Option.None1|typenope=Option.None|^^^^^^^^^^^|type`None` is not a member of Option- did you mean `Option.None`?
scala>typenope=Option.None.type// defined alias type nope = Option[Nothing](Option.None)
Note that the type of the expressions above is always Option. That is, the implementation case classes are not visible in the result types of their apply methods. This is a subtle difference with respect to normal case classes. The classes making up the cases do exist, and can be unveiled by constructing them directly with a new.
Related to #5221
One question about enums, https://dotty.epfl.ch/docs/reference/enums/adts.html
Is the
Option.Some
type visible? Is it legal to reference it like thisdef get(some: Option.Some[Int]) = some.x
?The text was updated successfully, but these errors were encountered: