There is a bit of wiggle room, you could argue that only the size of T should be depended upon and this shouldnāt be a full dependency on T itself, but as far as I know Zig currently doesnāt have such fine grained dependency tracking and instead just expects the programmer to write it in such a way, so that you donāt make your type depend on more than you intended.
Or said another way, I think both behaviors are a reasonable thing to want based on use-case, so it seems reasonable to have a way to write each of them.
So, can I describe the rule as: Two generic types are equal if their definition locations are the same and their substituted textual representations are equal? Two textual representations are equal if every pair of the corresponding types identifiers appearing in them represent the same value.
I do think this is better. Itās subtle, but there are a few places where Zig cuts comptime-knowability propagation short of where it could. Another example is that you canāt pass a mutable var via anytype into a function returning a type, even if all you do with it is examine the type.
The behavior isnāt wrong in any sense: itās a decision to resolve things a certain way. I believe there are benefits to be had from taking it further, but making that case will be long and abstruse and is going to have to wait for another occasion.
I will say this: explaining whyfoo ācapturesā T, and bar does not, is difficult. Thatās motive to make it easier, although countervailing reasons not to may prove sufficient.
Actually I dislike this particular example when the function is inlined. This made it very inelegant to make work my ranged-integer functions work with both regular int and comptime-integers.