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

Bug 330002

Summary: Wrong linearization of tsuper calls in diamond inheritance
Product: [Tools] Objectteams Reporter: Stephan Herrmann <stephan.herrmann>
Component: OTJAssignee: Stephan Herrmann <stephan.herrmann>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3    
Version: 0.7.1   
Target Milestone: 2.8.3   
Hardware: Other   
OS: Linux   
Whiteboard:

Description Stephan Herrmann CLA 2010-11-11 09:39:29 EST
After fixing bug 326969 it turns out that one specific kind of tsuper call
is wrongly resolved:

public team class Team0 {
	protected abstract team class TeamA {
		protected abstract class R {
			protected void print() { System.out.println("topR"); }
		}
		public void test() {
			System.out.println("topT");
			new R().print();
		}
	}
	
	protected team class TeamB extends TeamA {
		protected class R {
			protected void print() {
				System.out.println("0B");
				tsuper.print();
			}
		}
		public void test() {
			System.out.println("TeamB");
			super.test();
		}
	}
}
public team class Team1 extends Team0 {
	@Override
	protected team class TeamA {
		@Override
		protected class R {
			@Override
			protected void print() {
				System.out.println("1A");
				tsuper.print();
			}
		}
		@Override
		public void test() {
			System.out.println("TeamA");
			tsuper.test();
		}
	}
	public static void main(String[] args) {
		new Team1().test();
	}
	void test() {
		new TeamB().test();
	}
}

At the level of TeamB/TeamA the correct sequence is invoked:

  Team0$TeamB   -super-> Team1$TeamA   -tsuper-> Team0$TeamA

However, the nested role skips the middle step:

  Team0$TeamB$R            -tsuper->             Team0$TeamA$R

Difference is:

- Team0$TeamB.super actually considers the dynamic type of the
  outer team yielding Team1$TeamA

- Team0$TeamB$R.tsuper is statically resolved to TeamA$R without
  respecting the dynamic type of the outer team, thus targeting
  Team0$TeamA$R as determined by the static call site within Team0.


I fix should be made inside the logic for bytecode copy from
Team0$TeamB$R to Team1$TeamB$R (replacing also outer teams with
the current outer team).
Comment 1 Stephan Herrmann CLA 2011-04-30 19:29:11 EDT
postponing.
Comment 2 Stephan Herrmann CLA 2011-05-08 15:09:32 EDT
Given that the compiler actually creates wrong code and that the fix
should (hopefully) be limited in scope we should try to address this
for the upcoming release.
Comment 3 Stephan Herrmann CLA 2011-05-15 10:16:16 EDT
There won't be a 0.8 release.
Comment 4 Stephan Herrmann CLA 2018-06-05 16:19:41 EDT
Bulk move to 2.8
Comment 5 Stephan Herrmann CLA 2020-03-06 16:59:23 EST
bulk move to 2.8.1
Comment 6 Stephan Herrmann CLA 2023-07-20 07:42:14 EDT
Bulk move to 2.8.3