Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 528057

Summary: [9] Need to signal when tsuper() ctor call is needed to initialize fields
Product: [Tools] Objectteams Reporter: Stephan Herrmann <stephan.herrmann>
Component: OTJAssignee: Stephan Herrmann <stephan.herrmann>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.6   
Target Milestone: 2.7.1   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=569756
Whiteboard:

Description Stephan Herrmann CLA 2017-12-02 19:13:48 EST
After bug 527743, calling a tsuper() ctor is necessary in more cases, because we no longer perform field initializations outside constructors.

This bug tracks implementation of a new compile error if tsuper() is missing in this situation.
Comment 1 Stephan Herrmann CLA 2018-06-05 16:19:40 EDT
Bulk move to 2.8
Comment 2 Stephan Herrmann CLA 2018-08-26 04:33:22 EDT
While working on this I detected two additional issues:

Explicit lifting constructors lacking generated role registration statements, leaving this._OT$base unassigned.

The default constructor in a role with implicit super is unfortunate: if nothing is written it would be nice if tsuper() is assumed, but a regular super() is used instead. Changing this at this point would, however, be a breaking change so I will not make such change.
Comment 3 Stephan Herrmann CLA 2018-09-03 17:25:08 EDT
This was implemented for via

http://git.eclipse.org/c/objectteams/org.eclipse.objectteams.git/commit/?id=b8c129fe8b89a7c02820ac64e0611d79ef5804f3
http://git.eclipse.org/c/objectteams/org.eclipse.objectteams.git/commit/?id=ad95e6e0922d7db93f1919b4a95783afdff94ee8

Solution description:

- new IProblem: RoleConstructorNeedingTSuperCall
  message is: Need to invoke a tsuper constructor because tsuper role ''{0}'' has field initializations.

- new bit in OTClassFlags attribute: OT_CLASS_HAS_FIELD_INITS
  needed to transport info about field initializers via .class

- fix Lifting.createLiftToConstructorDeclaration():
  (needed for ImplicitInheritance.testFieldInitialization5_bound_NOK())
  Don't replace explicit super() in lifting constructor with tsuper().

- fix Lifting.isLiftingCtor(MethodBinding
  Need to recognize lifting ctor also in its tsuper shape.

- test adjustments:
  - add mandatory tsuper()
  - CallinMethodBinding.test4112_callinBindingMultipleBaseMethods2():
    avoid conclict in sub's lifting constructor: if we'd add the mandatory
    tsuper() call, runtime throws:
org.objectteams.IllegalRoleCreationException: Cannot instantiate a bound role using a default constructor of its tsuper class
    at Team4112cbmbm2_2$__OT__Role4112cbmbm2.<init>(Team4112cbmbm2_2.java:3)
    at Team4112cbmbm2_2$__OT__Role4112cbmbm2.<init>(Team4112cbmbm2_2.java:4)
    at Team4112cbmbm2_2._OT$liftTo$Role4112cbmbm2(Team4112cbmbm2_2.java:3)

    TODO: check how the compiler could catch this!