Subject: bug#65051: internal_equal manipulates symbols with position without checking symbols-with-pos-enabled.

From: Dmitry Gutov <[email-masked]>
Date: Fri, 11 Aug 2023 21:15:12 +0300

Hi Alan,

On 11/08/2023 17:04, Alan Mackenzie wrote:

>>   >  Currently, the working of s-w-p-enabled is inconsistent, and
>>   >  should be fixed, which is what this bug is about.
> 
>> Inconsistent with what?
> 
> With its definition: when s-w-p-enabled is non-nil, SWPs are handled
> specially.  When it's nil, they're not (or, at least, shouldn't be).

Point taken. So either the behavior needs to be changed, or the 
docstring updated.

>> If we're talking about the relation between EQUAL and EQ, objects that
>> are EQ have to be EQUAL, but those that are EQUAL don't have to be EQ.
> 
> I wasn't talking about that relationship, no, but there is no danger to
> it in fixing the current bug (or, indeed, in leaving it unfixed).

Yep.

>> Anyway, I'd like to offer a question from a different perspective:
>> should two symbols-with-positions where the positions are different but
>> the symbol is the same, be equal between each other?
> 
> Yes, when and only when symbols-with-pos-enabled is non-nil.
> 
>> If yes (which is my reading of fns.c:2755), then it makes sense for
>> them to be equal-able to symbols without positions as well.
> 
> Again, this should be the case when s-w-p-enabled is non-nil and only
> then.

All right, that also makes sense.

And I can see some theoretical benefit to not having these kinds of 
objects be 'equal' in contexts where that is not anticipated in advance 
(and so the variable is not bound). Especially in a stronger-typed 
language where such comparison or pattern matching could result in an 
error (e.g. comparing incompatible types). In our case, since we're just 
talking about 'equal', the comparison could result in execution just 
falling though and e.g. some bytecomp optimization not being applied, 
silently (hence the talk of "if not broken don't fix it").

It would be nice to see a piece of code that would benefit from the 
distinction. The reverse example I can imagine myself (some pcase form 
outside of any such binding, whether by accident or not).