I agree the current behavior and workaround here are not ideal. It really is a shame implicit member syntax doesn't work in this position.
I'm thinking about this pitch with regards to Doug's post from the if
/switch
expressions review about replacing the magic of result builders with more general source-generation features:
On its face, it seems like this would dig us deeper down the hole of 'magic' for supporting an ergonomic experience for result builders, and its not immediately clear how we'd dig ourselves back out if we wanted to achieve the goal of making result builders be 'just' a macro feature.
So I have a couple different thoughts on the pitch as-is:
- Are there existing language language features that we could improve to work around the issues presented here? Implicit member syntax almost works, is there any way we could tweak parsing rules to get it fully working, or not?
- If not, is there a more general language feature looming behind this extension of result builders? This feels very similar to how Kotlin lets you rebind
this
within a closure scope so that lookup can find names outside the strict lexical context. We don't necessarily need to make that part of this pitch, but it would be nice to know that we're not introducing a feature just for result builders that will make it significantly more difficult to generalize them later.