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
{{ message }}
Repository navigation
Generalize constant equality to use primitive equality #1811
In order for an object o to be an element in a constant set, o must have primitive equality. Similarly, if o is used as case e in a switch statement where e evaluates to o, o must have primitive equality.
In general, we require that an object must have primitive equality in order to be used in a constant expression in a manner where equality must be tested.
However, the exception (for historical reasons) is operator == itself!
This issue is a proposal to generalize the rule about operator == such that it also relies on primitive equality. We would change the language specification from
An expression of the form \code{$e_1$\,==\,$e_2$} is potentially constant
if $e_1$ and $e_2$ are both potentially constant expressions.
It is further constant if both $e_1$ and $e_2$ are constant and
either $e_1$ evaluates to an object that is an instance of
\code{int}, \code{double}, \code{String}, \code{bool} or \code{Null},
or if $e_2$ evaluates to the null object (\ref{null}).
to something like this:
An expression of the form \code{$e_1$\,==\,$e_2$} is potentially constant
if $e_1$ and $e_2$ are both potentially constant expressions.
It is further constant if both $e_1$ and $e_2$ are constant, and
$e_1$ has a primitive operator \lit{==}
(\ref{theOperatorEqualsEquals}),
or $e_2$ evaluates to the null object (\ref{null}).
Note that this proposal implies that enum values can be used as operands to == in a constant expression, cf. #312.
Reacted by Mateus Felipe C. C. Pinto, Lasse R.H. Nielsen, Olzhas Suleimen, Bob Nystrom, Alex Li, :o:, Mehmet Esen, Daniel Brauner, via-guy, ndelanou and 16 more
I haven't been tracking the implementation status but I do expect it to be implemented at some point in time since we (the language team) accepted the change.
Activity
lrhn commentedon Aug 19, 2021
LGTM.
leafpetersen commentedon Aug 19, 2021
This also seems fine to me.
AlexV525 commentedon Dec 22, 2021
This is blocking us to apply restrictions for assertions that are added to the constant constructor, where we don't want users to make such type.
If it's not going to push recently or it'll be a quite big change, I want to know how should I solve such requirement:
eernstg commentedon Dec 22, 2021
You should be able to use
identical:eernstg commentedon Feb 1, 2023
@munificent, do you expect this one to be implemented now, following dart-lang/sdk#51045? Nobody has mentioned any reason not to do this.
munificent commentedon Feb 27, 2023
I haven't been tracking the implementation status but I do expect it to be implemented at some point in time since we (the language team) accepted the change.
eernstg commentedon Feb 28, 2023
Cf. dart-lang/sdk#51565.
Fix enum instances comparison to use `equality ==` since dart has the…
Replace more enum instances comparison to use `equality ==` instead o…
`[cupertino_ui]` replace identical checks with equality when dealing …
`[cupertino_ui]` replace identical checks with equality when dealing …
`[material_ui]` replace identical checks with equality when dealing w…
`[cupertino_ui]` replace identical checks with equality when dealing …
`[material_ui]` replace identical checks with equality when dealing w…
Update more enum instances comparison to use equality == since dart h…