Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong static type on == #2369

Closed
johnniwinther opened this issue Nov 14, 2023 · 1 comment
Closed

Wrong static type on == #2369

johnniwinther opened this issue Nov 14, 2023 · 1 comment
Assignees
Labels
bad-test Report tests in need of updates. When closed, the tests should be considered good

Comments

@johnniwinther
Copy link
Member

The test co19/LanguageFeatures/Extension-types/static_analysis_member_invocation_A01_t05 assumes that the static type of == can be derived from the return type of the declared operator == method:

class B implements A {
  ...
  @override
  BoolET operator ==(Object? other) => BoolET(other == this);
}
...
extension type ET2(B b) implements ET1, B {}

extension type BoolET(bool b) implements bool {}

void main() {
  var e2 = ET2(B());
  ...
  BoolET b2 = e2 == e2;
}

Here e2.== can be found to have type BoolET Function(Object?) as declared in B.

If the latest spec is to be believed, the static type of an equality expression is always defined to be bool: (§17.27: "The static type of an equality expression is bool.")

cc @eernstg

@sgrekhov sgrekhov self-assigned this Nov 14, 2023
@sgrekhov sgrekhov added bad-test Report tests in need of updates. When closed, the tests should be considered good needs-info Additional information needed from the issue author labels Nov 14, 2023
@eernstg
Copy link
Member

eernstg commented Nov 14, 2023

Right, an equality expression has the type bool no matter what the declaration of the member named == says. I guess the reason is that an equality expression does more than just call operator == on the left hand operand (it performs a couple of tests for null).

This means that "treated as all other non-extension type members" in the test description is true even for ==. However, an expression of the form e1 == e2 is given an unusual treatment in all cases (when it occurs in the interface of the class B, and also when it occurs in the interface of the extension type ET2).

It would probably be helpful for future readers to add a comment like '// The type of an equality expression is always bool.' just before bool b2 = e1 == e2;.

@sgrekhov sgrekhov removed the needs-info Additional information needed from the issue author label Nov 14, 2023
sgrekhov added a commit to sgrekhov/co19 that referenced this issue Nov 14, 2023
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Nov 17, 2023
2023-11-17 sgrekhov22@gmail.com Fixes dart-lang/co19#2381. Fix roll failures (dart-lang/co19#2382)
2023-11-16 sgrekhov22@gmail.com Fixes dart-lang/co19#2379. Update expected error position for CFE (dart-lang/co19#2380)
2023-11-16 sgrekhov22@gmail.com Fixes dart-lang/co19#2377. Add missing Float32x4List.setAll_A04_t01 test (dart-lang/co19#2378)
2023-11-16 sgrekhov22@gmail.com Fixes dart-lang/co19#2373. Expect additional errors in CFE for member conflicts tests (dart-lang/co19#2375)
2023-11-16 sgrekhov22@gmail.com dart-lang/co19#2359. Fix existing extension types tests according to the new nullability rules (dart-lang/co19#2372)
2023-11-16 sgrekhov22@gmail.com Fixes dart-lang/co19#2356. Fix nullability in dynamic_semantics_member_invocation_A03_t02.dart (dart-lang/co19#2368)
2023-11-16 sgrekhov22@gmail.com dart-lang/co19#2371. Add tests for factory constructor generating an enum value (dart-lang/co19#2376)
2023-11-15 sgrekhov22@gmail.com dart-lang/co19#2371. Add missing enhanced enums tests, update assertions (dart-lang/co19#2374)
2023-11-14 sgrekhov22@gmail.com Fixes dart-lang/co19#2369. Static type of == operator is always bool (dart-lang/co19#2370)
2023-11-14 sgrekhov22@gmail.com dart-lang/co19#2303. Add more File.create()/createSync() tests (dart-lang/co19#2337)
2023-11-10 sgrekhov22@gmail.com dart-lang/co19#2339. Add test for extension named type and a record type (dart-lang/co19#2366)

Change-Id: If608421c5a4f614187a66dc05fa5d8d90c9e363d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336901
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bad-test Report tests in need of updates. When closed, the tests should be considered good
Projects
None yet
Development

No branches or pull requests

3 participants