3 ms·
Today I caught a bug in a macro-expanding code walker, where it was expanding the wrong form. The syntax being walked is (foo-special-operator x y z . rest). x
by kazinator 10y ago
Today I caught a bug in a macro-expanding code walker, where it was expanding the wrong form. The syntax being walked is (foo-special-operator x y z . rest). x and z are ordinary forms that need to be expanded; y is a destructuring pattern (irrelevant here). The walker was expanding z in the place of x: that is to say, expanding z twice, and using that as the expansion of both x and of z. That's simply due to a typo
referring to the wrong variable.
The type system would be of donkey all use here, because everything has the correct type, with or without the mistake. The code referred to the wrong thing of exactly the right type.
A lot of code works with numerous variables or object elements that are all of the same type, and can be mixed up without a diagnostic.
- neilparikh 10y agoSo the issue you faced was that you used z twice, and x not at all? In that case, linear types (http://edsko.net/2017/01/08/linearity-in-haskell/ http://edsko.net/2017/01/08/linearity-in-haskell/) may have caught that.
- kazinator 10y agox not being used at all can be caught by a simple unused variable warning. In this situation, the variable's value was used somewhere, so that didn't go off.
- codygman 10y agoIf you used newtypes for z and x it would have been caught.