-
Notifications
You must be signed in to change notification settings - Fork 228
Open
Labels
enhanced-constRequests or proposals about enhanced constant expressionsRequests or proposals about enhanced constant expressionsfeatureProposed language feature that solves one or more problemsProposed language feature that solves one or more problems
Description
There is a request to add an annotation for parameters whose semantics ensures that the argument corresponding to the annotated parameter is a constant expression.
It occurred to me that this might be an interesting language feature. The proposal would be to allow the modifier const on parameter declarations and for the semantics to match those requested for the annotation. For example,
void f(const List<int> x) {}
void g(int a) {
f(const [1, 2, 3]); // OK because it's explicitly const.
f([1, 2, 3]); // OK because it's implicitly const.
f([a]); // ERROR because `a` isn't a valid const expression
}
It might additionally provide some possibilities for compiler optimizations if it's known that the value of the parameter can't be modified.
I suspect that we'd want to introduce the annotation first and see how/whether it's used in practice, but I thought I'd mention it in case you'd want to track the work on the annotation.
srawlins, parlough, ykmnkmi, Semvrij, mateusfccp and 10 morealbertms10avdosev, jellynoone, Number-3434 and albertms10
Metadata
Metadata
Assignees
Labels
enhanced-constRequests or proposals about enhanced constant expressionsRequests or proposals about enhanced constant expressionsfeatureProposed language feature that solves one or more problemsProposed language feature that solves one or more problems