dart-lang / dart-lang/language
Const asserts
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Today I encountered an issue where I needed to ensure that some constants are edited correctly to prevent a runtime error. While it's possible to write a StaticAssert class like this:
```dart
class StaticAssert {
const StaticAssert(bool value, [String message = 'Assertion failed']) : assert(value, message);
}
```
Using it is somewhat difficult, since the analyzer complains about unused variables:
```dart
const _asserts = [
_StaticAssert(a <= b),
_StaticAssert(c <= b),
];
```
It would be a bit better if you could write a top level assert:
```dart
const assert(a <= b);
const assert(c <= b);
```
Which is sorta like `static_assert` in C++11.
Contributor guide
Research direction
Start with the StaticAssert example and the proposed top-level const assert syntax in the issue. Determine the language-design rules and specification changes needed for compile-time assertions, including how constant expressions and messages should behave; done means the proposal has a resolved design.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100