Super Weird Bug
jherdman opened this issue · comments
Bear with me on this, but if you want to jump to the fun bits, here's the sample app https://github.com/jherdman/angle-bracket-bug
The gist is this:
(Obviously I'm defining availableOptions
as an array of values)
Results in this:
The problem goes away if I change the yielded param's name, e.g. option
to opt
.
👋 - I suspect that things are working appropriately here.
This situation is specifically discussed in this section of the RFC. Here is a small snippet:
Notably, based on the rules laied out above, the following is perfectly legal:
From a programming language's perspective, the semantics here is quite clear. A local variable is allowed to override ("shadow") another varible on the outer scope (the "global" scope, in this case), similar to what is possible in JavaScript:
let console = { log() { alert("I win!"); } }; console.log("Hello!"); // shows alert dialog instead of logging to the consoleWhile this is semantically unambigious, it is obviously very confusing to the human reader, and we don't recommend anyone actually doing this.
A previous version of this RFC recommended statically disallowing these cases. However, after giving it more thoughts, we realized it should not be the programming language's job to dictate what are considered "good" programming patterns. By statically disallowing arbitrary expressions, it actually makes it more difficult to learn and understand the underlying programming model.
You and me both!