Opened 5 months ago
#308 new enhancement
Unused Polymorpic Parameters
Reported by: | ajbeach | Owned by: | |
---|---|---|---|
Priority: | minor | Component: | cfa-cc |
Version: | 1.0 | Keywords: | |
Cc: |
Description
I think we should consider detecting and reporting unused polymorphic attributes and possibly assertions on functions and type definitions.
It might look like this:
forall([[maybe_unused]] T) void example([[maybe_unused]] int test, int) {} forall(T | [[maybe_unused]] arithmetic( T ) ) struct rational { T numerator; T denominator; };
Now we already have a way to specify an unused parameter, leave it unnamed. This is used in the second parameter to example, but doesn't work for forall clauses because the names are part of the syntax for both parameters and assertions.
We would need to insert an extra pass, but if we get that far we could probably have a big pass that does all the extra warning checks. If there is any use of a polymorphic parameter, it is fine, if there is any function in an assertion that is used, the entire assertion is fine.
From an actual language design perspective though, most languages with similar features don't have similar errors. Even if a lot of those cases turn out to be unnecessary one additional wrinkle we have in this language is there are multiple ways to declare the parameters and it is pretty easy to use one that is more robust than required and that can significantly change the underlying code, so this should generate a warning:
forall(T) struct Data { T * data; };
If a use case does require assertions than the compiler expects, you could write T & | sized(T)
(possibly with [[maybe_unused]]
to indicate to the compiler that it is on purpose. Same idea with is_value
and is_object
.