#1313 Require Operator facet on add for comma operator

Henri Sat 13 Nov 2010

Shouldn't we be able to overload the add method (used by the comma operator in it-blocks) as well? Currently it can't be annotated with @Operator.

qualidafial Sat 13 Nov 2010

That could actually be pretty cool, but there's overlap here with serialization that needs to be dealt with.

Take for example a Contact class:

@Serializable { collection = true }
class Contact
{
  @Transient readonly PhoneNumber[] phones
  @Operator This addPhone(PhoneNumber phone)

  @Transient readonly Address[] addresses
  @Operator This addAddress(Address addr)
}

In order for this class to be serialized properly, the each method needs to iterate both collections:

Void each(|Obj kid| f)
{
  phones.each(f)
  addresses.each(f)
}

However the loss of type safety here is kind of ugly. Another option is to require that for each @Operator-annotated add method, there is also a correspondingly named each method:

Void eachPhone(|Phone kid| f)
{
  phones.each(f)
}
Void eachAddress(|Address kid| f)
{
  addresses.each(f)
}

This would require some rework in both the compiler as well as the serialization code.

One more thought: what if (now that slots are serializable) we identified the add and each methods in the @Serializable facet?

@Serializable
{
  collections = [
    #addPhone : #eachPhone,
    #addAddress : #eachAddress
    ]
}

Just an idea..

brian Sat 13 Nov 2010

Well I don't think it makes sense to support multiple each/adds - that starts to seem too complex.

So the question is should we require add to be annotated with the @Operator method? Personally I have mixed feelings so it is sort of a very different. But at the same time requiring it to be annotated seems a little safer for future proofing.

qualidafial Sat 13 Nov 2010

I think for consistency it makes sense to require it for add, at least if you want compiler sugar to apply with the , comma "operator."

Henri Sat 13 Nov 2010

I suppose this is one of those situations where naming conventions can be a bit awkward. We have an add method that is used for two similar situations, but this may not always be what you want. If the serialization process used annotations for the each and add methods, for example, we could use different method names to avoid collisions.

brian Sat 13 Nov 2010

Promoted to ticket #1313 and assigned to brian

Yeah, it probably makes sense to force add to use the @Operator facet.

However, I am not ready to say we allow overloading - especially given this is issue overlaps serialization

brian Sun 2 Jan 2011

Renamed from Add method overloading to Require Operator facet on add for comma operator

brian Sun 2 Jan 2011

Ticket resolved in 1.0.57

Updated compiler to require the @Operator facet on the add method in order to use the comma operator. This will be a breaking change to code using that pattern.

changeset

Login or Signup to reply.