Hacker News new | ask | show | jobs
by cbHXBY1D 3563 days 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?

1 comments

Sure, the AST node for "when" is here: 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#L...