Proposal: Allow var to appear recursively in ParamDecl #3642
Labels
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Abstract
Allow
var
to appear inside generic arguments in the context of ParamDecl.Problem
Considering the following generic:
When instantiating generics, an anonymous struct is created and cached for subsequent call to the generic with the same arguments.
While it is possible to get a type from a generic and some arguments (
generic + arguments = type
), it is not possible to get back the arguments from a generic and a concrete type (type - generic = arguments
).In order to have access the arguments of a generic, the values must be passed explicitly as other arguments to the function:
Proposal
This proposal is to refine the use of
anytype
in the context of ParamDecl by allowing it to appear in arguments of generics like so:Adding this feature to the language may also help prevent errors when using generic APIs like
std.fmt
, while being more helpful for language tools.There is no need to add additional syntax or keywords to facilitate the extraction of the generic arguments' values, as simply exposing them as
const
values on the returned struct itself will allow one to get back the values with@typeOf(...).Arg
.Discussion
I believe this would required a change to the grammar to allow KEYWORD_anytype inside TypeExpr and do a validation pass on TypeExpr inside ParamDecl that are using KEYWORD_anytype.
If such a proposal is accepted, would it make sense to allow
KEYWORD_anytype
to also appear in all TypeExpr like variable declarations and return types, assuming that eachanytype
resolves to a single concrete sized type at compile time ?The text was updated successfully, but these errors were encountered: