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

Specify the context type for the index in an increment/decrement operation #2271

Open
eernstg opened this issue Jun 2, 2022 · 2 comments
Open
Labels
question Further information is requested specification

Comments

@eernstg
Copy link
Member

eernstg commented Jun 2, 2022

The context type for an expression of the form e1[e2]++, e1[e2]--, ++e1[e2], --e1[e2] is apparently not specified.

In the case where the corresponding operator declarations have parameter types T1 and T2 for the index, the most general type that would work is the greatest lower bound of T1 and T2, so we would most likely use the standard lower bound (which is an approximation of the greatest lower bound).

class C {
  T0 operator[](T1 index) ...
  operator[]=(T2 index, T3 value) ...
}

X whatever<X>() {
  print(X);
  throw 0;
}

void main() {
  C()[whatever()]++; // Prints the standard lower bound of `T1` and `T2`.
}
@scheglov
Copy link
Contributor

scheglov commented Jun 2, 2022

When you say "standard lower bound" do you mean https://github.com/dnfield/dart-sdk/blob/master/docs/language/informal/extreme-upper-lower-bounds.md? When I read it, I see which properties it should have, but not the way it is computed, specifically SUB(S, T) == SUB(T, S) is a mystery.

However there is https://github.com/dart-lang/language/blob/master/resources/type-system/upper-lower-bounds.md, which defines DOWN.

@eernstg
Copy link
Member Author

eernstg commented Jun 3, 2022

I'm proposing the phrases 'standard upper bound' and 'standard lower bound' in this PR where a number of new sections from the overall null safety update to the language specification are added. That is again the result of integrating several documents including https://github.com/dart-lang/language/blob/master/resources/type-system/upper-lower-bounds.md into the language specification. Sorry, I forgot for a moment that this phrase is in text that hasn't yet landed.

It is not intended to differ from the functions that we've called "least upper bound" and "greatest lower bound" which are already implemented and used as part of the current language version (I don't remember precisely when those functions were changed most recently, but they have been essentially unchanged during all null safety language versions).

https://github.com/dnfield/dart-sdk/blob/master/docs/language/informal/extreme-upper-lower-bounds.md is old, and has been subsumed by more recent documents. We do have this remark in the README.md:

This directory contains background material only.

but it would probably be better to mark every single document with the same warning, or to remove them entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested specification
Projects
None yet
Development

No branches or pull requests

2 participants