> On May 24, 2019, at 10:34 AM, Brian Goetz <brian.go...@oracle.com> wrote: > > > var yield = 5; > > yield is lexed as an identifier, so this is a valid variable declaration > > var res = switch(yield) { > > yield is lexed as an identifier, so this is a valid switch operand > > > default -> yield + yield; > > RHS of a single-consequence case is expression | block statement | throw. > We're not in a YieldStatement production, so this is an expression. > > Like lambdas, we can think of this as shorthand for > > default -> { > yield yield + yield; > } > > which parses as a yield statement whose operand is the expression yield+yield.
And, yay (thanks, Tagir), default -> { yield + yield; } is a genuine, bona fide puzzler! (But as long as we are doing special-case parsing and checking the next token right after an occurrence of yield, it is a puzzler we can easily defend against if we want to.) —Guy