-
Notifications
You must be signed in to change notification settings - Fork 424
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
Proposed support for Reflection functions that get type of generic var/const fields from a type variable #12167
Comments
For clarity, we can do this today for typed fields: record R {
param value: int;
}
var r = new R(1);
type t = r.type;
writeln(t.value); // prints 1 Unfortunately, this doesn't work so well for array type/param fields, due to the layers of abstraction, but there are some ways we might address this, e.g. adding type/param accessor methods for those fields or removing those layers of abstraction for those type/param fields (#12166). I think #8543 captures this feature request. |
Recording here for visibility - we discussed this in chat. I hadn't realized that the param and type cases worked when arrays weren't involved. My main focus was allowing us to get the type of generic var/const field when the type is instantiated, so I've updated the PR title to reflect that. I would still expect the functions to work for both type/param and generic var/const fields |
If we went with the proposals in the issue text above, I'd probably call them That said, I'd prefer to get at the type of the field directly through the language syntax as proposed in issue #11816 rather than needing to use reflection. |
Updated to reflect that suggestion. I would also prefer to get it directly through the language, but I suspect implementing this is almost trivial so could be a good interim step. If we prioritize the other one quickly, though, I would be fine with closing this without implementing it |
If you were going to invest time implementing one of these two, I'd much rather have you implement the other. |
Looking at this again after some time has passed, while I still prefer the language-based syntax for querying a field's type (which I captured today in #26444), the first of the two routines Lydia proposes here has the benefit of not needing to know a field's name to determine its type (e.g., I could iterate over the fields querying all of their types). Given the time that's passed since we opened this, I'd also rather have the second routine than no capability to query a field's type at all. I put a user issue tag on this because, cleaning up my inbox at the end of the year, I found such a request (from quite awhile back). |
Here are the function prototypes I would expect to see based on what is currently present. Such functions would use
PRIM_STATIC_FIELD_TYPE
, as mentioned in #11816The text was updated successfully, but these errors were encountered: