-
Notifications
You must be signed in to change notification settings - Fork 213
const correctness like in C++ #1567
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
Comments
Knowing that calling One question is whether it would be shallow or deep. Can a Should there be a way to circumvent the The It would mean that function types would need to be |
|
Note that there is no soundness guarantee from struct A {
int x;
A* v;
void foo() const {
use(this->x);
v->x = 11;
use(this->x); // Is x the same? Nobody knows because |v| might be the same as |this|
}
}; This also means that compiler usually can't really use |
possible case: // lib
class Route {
const Route(this.path);
final String path;
}
class App {
// ...
Route route(const String path) {
return const Route(path);
}
}
// code
const app = App('app');
@app.route('/')
void hello() {
// ...
} |
Just pointing out that this syntax can conflict with #1684 |
@Levi-Lesches is this issue still open?? |
@guneshmunjal, I'm not part of the Dart team nor the original author, but yes, it appears to still be open, but I don't know how high of a priority it is at the moment. |
I like I'm going to close this out because I can't see us realistically taking this on. |
I'd love const correctness for parameters and methods similar to C++.
If I mark a method as const, it guarantees, that calling it won't change the instance.
If I mark parameters as const, it guarantees, that calling it won't change the parameters.
In C++ this feature is a great assistance to avoid side effects and helps the compiler to optimize.
Example implementation would be:
The text was updated successfully, but these errors were encountered: