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

Bug 329374

Summary: Implicit Lowering of a Role Array as return results in compiler error
Product: [Tools] Objectteams Reporter: Jan Marc Hoffmann <exelnet>
Component: OTJAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 0.7.1Flags: stephan.herrmann: iplog+
Target Milestone: 0.8 M4   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
test & fix
none
fix for the remaining problem none

Description Jan Marc Hoffmann CLA 2010-11-03 12:50:57 EDT
I just found this odd behaviour:

The following error is thrown in this code:

No enclosing instance of the type MyTeam is accessible in scope
(Compiler Error, please report)


The code:


package otb;

public class Main {

	public static void main(String[] args){
		MyTeam t = new MyTeam();
		B b = new B();
		A[] as = t.getAs(b);
	}
}

package otb;

public team class MyTeam {

	protected class RoleA playedBy A {
 
	}
	
	protected class RoleB playedBy B {
		protected RoleA[] getAs(){
			return new RoleA[0];
		}
	}
	
	public RoleA[] getAs(B as RoleB rb) {
		return rb.getAs();
	}
}

It works fine if either used without an array or by returning the basetype array in the getAs() method.

greetings

Jan Marc
Comment 1 Stephan Herrmann CLA 2010-11-03 18:05:53 EDT
I can reproduce, thanks for the report.
Comment 2 Stephan Herrmann CLA 2010-11-05 15:56:16 EDT
Created attachment 182523 [details]
test & fix
Comment 3 Stephan Herrmann CLA 2010-11-05 16:02:23 EDT
Patch has been committed as r983 f.
Comment 4 Stephan Herrmann CLA 2010-11-08 08:19:52 EST
When trying this fix in real life, the OT builder throws:

need to create transform method, but have no source type: otb.MyTeam
	at org.eclipse.objectteams.otdt.internal.core.compiler.lifting.ArrayTranslations.ensureTransformMethod(ArrayTranslations.java:146)
	at org.eclipse.objectteams.otdt.internal.core.compiler.lifting.ArrayTranslations.translateArray(ArrayTranslations.java:98)
	at org.eclipse.objectteams.otdt.internal.core.compiler.lifting.ArrayLowering.lowerArray(ArrayLowering.java:55)
	at org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lowering.lowerExpression(Lowering.java:95)
	at org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.InsertTypeAdjustmentsVisitor.maybeWrap(InsertTypeAdjustmentsVisitor.java:320)
	at org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.InsertTypeAdjustmentsVisitor.endVisit(InsertTypeAdjustmentsVisitor.java:113)
	at org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.InsertTypeAdjustmentsVisitor.endVisit(InsertTypeAdjustmentsVisitor.java:86)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.traverse(LocalDeclaration.java:317)

Here we indeed have a problem: the type Main requires that MyTeam has an
array-lowering method, but it may be too late to generate that method when the
need is detected. I don't see an easy fix right now.
Comment 5 Stephan Herrmann CLA 2010-12-04 18:35:33 EST
Created attachment 184546 [details]
fix for the remaining problem

The remaining problem has been fixed by generating array lowering for
all externally visible methods returning an array of roles.

I forced the test to run into this issue by defining a compileOrder.
Comment 6 Stephan Herrmann CLA 2010-12-04 18:37:25 EST
Second fix has been committed as r1124 f.
Comment 7 Stephan Herrmann CLA 2010-12-16 15:03:44 EST
Verified for M4 using build 201012150343
Comment 8 Stephan Herrmann CLA 2011-05-10 09:29:11 EDT
Setting the iplog flag to acknowledge the contributed test case in comment 0.