4 ms·
> No, it's closer to template expansion, "when" is "executed" (for lack of a better word) during compilation. Inactive "when" branches are ignored by the code g
by cbHXBY1D 10y ago
> No, it's closer to template expansion, "when" is "executed" (for lack of a better word) during compilation. Inactive "when" branches are ignored by the code generator (and type checker, thus they can contain code that's invalid for given instantiation). There's no type-switch in the resulting Go code.
I'm not sure I understand. Could you point to where you do this on Github?
- wowoc 10y agoSure, the AST node for "when" is here: https://github.com/vrok/have/blob/master/have/ast.go#L159 https://github.com/vrok/have/blob/master/have/ast.go#L159 Type checker checks the condition before every branch in "when" statements, and sets the "True" flag if it evaluated to true. Then the code generator just skips over branches that don't have the "True" flag set: https://github.com/vrok/have/blob/master/have/generator.go#L728 https://github.com/vrok/have/blob/master/have/generator.go#L...