dart-lang / dart-lang/language

[Question] Using `==` directive vs. in constant Set literal

Open
#2,540 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

I have a trouble with understanding when `==` should be invoked, and when it is allowed.

```dart
const d = dynamic;
const i = int;

void main() {
  const a = {d, i};
  const b = d == i;
}
```

We report a compile-time error for `b`, because `==` can only be invoked on `Null`, `bool`, `int`, `double`, or `String`.
So, when we attempt to evaluate it, we detect and error, and throw an exception.

But at the same time the specification for constant Sets says:
![image](https://user-images.githubusercontent.com/384794/193331950-537fe6f0-cdc8-4e83-8677-403fce373259.png)

Currently implementations consider `{d, i}` to be OK.
But why? It invokes `==` just like `d == i`, except that it does it implicitly.

Contributor guide

Open the contributing guide

Research direction

Read the constant-set specification alongside the examples using `const d = dynamic`, `const i = int`, `{d, i}`, and `d == i`. Determine whether the differing treatment of implicit equality in constant sets is intentional, then clarify the specification or document the resolution so the two cases are consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.