Ticket #237 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years ago

Generic declared lifting should work accross team inheritance

Reported by: stephan Owned by: stephan
Priority: major Milestone: OTDT_1.2.8
Component: compiler Version: 1.2.7
Keywords: Cc: sbeaumont@…

Description

sbeaumont provided an example with roles bound to Object so he could use declared lifting:

public team class SuperTeam {
    protected class GeneralizedRole playedBy Object { /* ... */ }
    public void processRole(Object as GeneralizedRole o) { /* ... */ }
}

He then implemented a sub-team providing concrete roles with more specific bindings:

public team class SubTeam extends SuperTeam {
    protected class SpecificRole 
                extends GeneralizedRole 
                playedBy SpecificBase 
    { /* ... */ }
}

While this works it would be even better if no playedBy was required in the SuperTeam. This could in principle be achieved by using generic declared lifting (see OTJLD §2.3.2(e)) like:

   public 
   <RBase base GeneralizedRole>
   void processRole(RBase as GeneralizedRole o) { /* ... */ }

However, the compiler now complains that the type RBase is not compatible (even to itself ;-). Comparing the OTJLD and the compiler implementation, the compiler is stricter than needed: while it is correct that for team SuperTeam no class can be found that is a base class of GeneralizedRole, the situation looks different for SubTeam.

So, we might want to make the implementation more capable by letting it compile the method as given above. Now, calling processRole on a variable of type SuperTeam will never typecheck for the given reason, however, using the same method on SubTeam should allow arguments of exactly those classes for which SubTeam provides a playedBy binding with a role compatible to GeneralizedRole, in this particular case: SpecificBase.

Change History

Changed 4 years ago by stephan

  • cc sbeaumont@… added
  • status changed from new to closed
  • resolution set to fixed
  • milestone set to OTDT_1.2.8

Implemented in r19827, r19832 and r19833:

  • Generate a new internal method _OT$lift_dynamic$''RoleX''
  • Redefine these lift_dynamic methods in each sub team to reflect its roles
  • Improve type checking for generic methods to reflect the actual receiver type during parameter substitution (i.e., invoking processRole on a SuperTeam variable will never type-check since RBase cannot be matched but invoking the same method on a SubTeam variable may compile).

An initial test is in A.1.9-otjld-basetype-parameter-9, more tests (esp. negative ones) still need to be written.

We should also check whether this pattern can also be applied to arrays.

Apart from these two TODOs this feature is implemented, local tests pass, next unstable release with this feature should be available later today.

Note: See TracTickets for help on using tickets.