You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the language should either allow variable shadowing all together, or dis-allow it all together, not have exceptions for when variables are shadowed inside if-statements like this.
The text was updated successfully, but these errors were encountered:
Jasper-Bekkers
changed the title
Shadowin variables inside of flow control don't produce shadowing warning
Shadowing variables inside of flow control don't produce shadowing warning
Oct 21, 2021
Just for clarity, I'll be pedantic and point out that the diagnostic message produced by the second case is an error and the exception isn't for if-statements but for different scopes. Placing the shadowing variable in an anonymous nested scope has the same effect of silencing the error.
Allowing variable shadowing in nested scopes is consistent with many languages that are both familiar to authors and the origin point of porting efforts. Parameters are considered in the same scope as the declared variables, so they are disallowed as being in the same scope.
In particular, this is how C++ behaves and how HLSL has always behaved. Our intent is to narrow the gap between HLSL and C++. I'm afraid this is inconsistent with that goal.
If you'd like warnings for whenever shadowing occurs even in this scenario, you can enable the -Wshadow flag.
This doesn't produce a shadowing warning:
http://shader-playground.timjones.io/f463aa8e1b9249b2dabc84168c522ff7
Whereas this does:
http://shader-playground.timjones.io/86bc74ba95742f8f45f7f398faa3e9d5
I think the language should either allow variable shadowing all together, or dis-allow it all together, not have exceptions for when variables are shadowed inside if-statements like this.
The text was updated successfully, but these errors were encountered: