dart-lang / dart-lang/language

(3.14,) == (3.14,) constant?

Open
#3,563 9 comments 2 reactions 0 assignees View on GitHub
enhanced-const question records
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

See https://github.com/dart-lang/sdk/issues/54638 for details.

The expression `(3.14,) == (3.14,)` is not constant, because `(3.14,)` does not have primitive equality, because it isn't true that every component has primitive equality, because `double` objects do not have primitive equality.

So the given expression is not constant.

However, `3.14 == 3.14` _is_ a constant expression, because we have added `double` objects as receivers of operator `==` in constant expressions as a special exception.

Should we generalize this to allow `double` components in records with `==` in constants? We probably don't want to say that `(3.14,)` has primitive equality, but we could say that `e1 == e2` is (also) a constant expression in the case where `e1` is a constant expression that evaluates to a record whose components are `double` objects or objects with primitive equality.

@dart-lang/language-team, WDYT?

Contributor guide

Open the contributing guide

Research direction

Start by reading the linked Dart SDK issue 54638 and the examples in this discussion, especially `(3.14,) == (3.14,)` and `3.14 == 3.14`. Review the language-team feedback to determine whether constant equality should be generalized to records containing doubles. Done means the semantics have a clear decision and the corresponding language specification work is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.