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
The problem is that we have a case class Failure that also happens to have a get method. This was not foreseen in our name-based pattern matching scheme, which triggers a get based match if there are get and isDefined members of the right types.
This is a general problem. Basically it means that no case class can have a get member, or we risk getting the wrong match.
To avoid the problem I propose to refine the name-based pattern matching scheme as follows.
If the result type of an unapply is a subtype of ProductN and it has an isDefined method,
the match succeeds with the result type itself.
If (1) does not apply and the result type of an unapply has a member of form
val isEmpty: Boolean or
def isEmpty: Boolean
and also has a member of form
val get: T or
def get: T
then the match succeeds with T if isEmpty is false.
This scheme has the advantage that it avoids accidental triggering of get matches and that it
is compatible with what scalac does.
odersky
added a commit
to dotty-staging/dotty
that referenced
this issue
Dec 14, 2016
This fails to compile with the following error:
Where the code is:
The text was updated successfully, but these errors were encountered: