Skip to content

No static warning for not void user-defined []= operator #42198

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

Closed
sgrekhov opened this issue Jun 5, 2020 · 4 comments
Closed

No static warning for not void user-defined []= operator #42198

sgrekhov opened this issue Jun 5, 2020 · 4 comments
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Jun 5, 2020

According to the Dart specification (10.1.1 Operators)

It is a static warning if the return type of a user-declared operator ‘[]=’ is
explicitly declared and not void.

In fact, there is an error in analyzer and no issues in VM

class C {
  int operator []=(index, value) => 42;
  operator[](index) {}
}

main() {
  C c = new C();
  c[0] = new C();
}

The program above produces
error - The return type of the operator []= must be 'void'
in analyzer and no errors or warnings in VM

Dart VM version: 2.9.0-13.0.dev (dev) (Fri May 29 15:59:05 2020 +0200) on "windows_x64"

@devoncarew
Copy link
Member

@sgrekhov - it sounds like the analyzer has correct behavior here, and we'll need to update the VM / CFE to have the same behavior?

@devoncarew devoncarew added the legacy-area-front-end Legacy: Use area-dart-model instead. label Jun 5, 2020
@sgrekhov
Copy link
Contributor Author

sgrekhov commented Jun 5, 2020

@devoncarew specifications states 'static warning' but analyzer produces 'compile error'. @eernstg please confirm if it is correct

@eernstg
Copy link
Member

eernstg commented Jun 8, 2020

This discrepancy has been known for a long time, cf. #36127 and #36126. Created dart-lang/language#1012 to settle the issue in the way that is based on discussions is the language team over time.

@johnniwinther
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

4 participants