-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Local variable is shadowed by a template parameter of an ancestor #146
Comments
Maybe I am missing some important difference between this and the issue previous to this one ( #144 )? |
The previous one had the nested template arguments overridden by a local variable due to call by name. This one, a variable inside a non-template struct gets overridden by a template parameter of the parent templated struct, where it should be scoped and not accessible without using .parent. |
Aren't both of them caused by the pattern language delaying assignment until needed in an evaluation? The value chosen is always the one in scope at the time of evaluation, not at the time of definition. |
Using name shadowing as part of the description of the bug is confusing and makes it harder to understand the actual bug being reported. It is not a matter of priorities in variable selection. The template argument is just not accessible to the inner pattern regardless of its name. The example code should emphasize the nature of the bug. A clearer example would have been: import std.io;
struct Inner {
std::print("{}",size);
};
struct Outer<auto size> {
Inner inner;
};
Outer<10> outer@0; which doesn't give errors and prints 10. Do the changes in your PR fix the real bug? the result of the code I posted should be an error but if you only made it so that the local variable is chosen first then the bug was not really fixed. |
The problem persists without the child struct. There are indeed two problems here. import std.io;
struct template<auto size>
{
u32 size = 16;
std::print("size: {}\nthis.size:{}\n", size, this.size);;
};
template<24> outer;
// I: size:24
// I: this.size:42 |
The text was updated successfully, but these errors were encountered: