Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354956 - Java Compiler errors on set-values block to initialize an array of delegates
Summary: Java Compiler errors on set-values block to initialize an array of delegates
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P1 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-17 10:44 EDT by Kathy Carroll CLA
Modified: 2017-02-23 14:17 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kathy Carroll CLA 2011-08-17 10:44:38 EDT
Java Compiler error

The method ezeSet(int, EglAny) in the type EglList<EglAny> is not applicable for the arguments (int, Delegate)
=============================  EGL CODE =================

library tester {}
    function runTests()
        // not ok
        runTestMtds runTestMethod[] = [EBoolean003.runTestConversions02,
EBoolean003.runTestConversions03];
    end
    function runtTests2()
        // ok
        runTestMtds runTestMethod[2];
        runTestMtds[1] = EBoolean003.runTestConversions02;
        runTestMtds[2] = EBoolean003.runTestConversions03;
    end
end

delegate runTestMethod()    
end

==================================

package explore;

// basic library
library EBoolean003 {}
    // Function Declarations
    function runTestConversions02()
    end

    function runTestConversions03()
    end

end
Comment 1 Kathy Carroll CLA 2011-08-19 13:26:04 EDT
Lowered importance because Jing is going to change the code generated by the test framework so we won't get this problem.
Comment 2 Jeff Douglas CLA 2011-09-14 15:21:31 EDT
I've talked at length with Tim on this. The testcase is invalid and needs to change. 

This technique is wrong for delegates because there is no type for delegates, so Paul you need to cause validation to prevent this style of coding:

runTestMtds runTestMethod[] = [EBoolean003.runTestConversions02, EBoolean003.runTestConversions03];


However, this is the acceptible style and the testcase should be changed to reflect this:
runTestMtd runTestMethod[] {EBoolean003.runTestConversions02, EBoolean003.runTestConversions03};
Comment 3 Matt Heitz CLA 2011-09-14 15:32:58 EDT
Jeff,

I think there should be a question mark on the element type of the array: runTestMethod?[] not runTestMethod[].

Variables of types that can't be instantiated, such as Any and delegates, must always be declared nullable.  So doesn't it follow that they must be nullable when they're elements of an array?

Did you go over this issue when you spoke with Tim?
Comment 4 Kathy Carroll CLA 2011-09-15 14:43:07 EDT
I've modified the code testcase to work like this.   I haven't closed the defect due to the open question about nullablty of delegates arrays.  I'll let development resolve this defect.

================================
package explore;
library tester {}
    function runtTests2()
        runTestMtds runTestMethod[]{EBoolean003.runTestConversions02,EBoolean003.runTestConversions03};
        runTestMtds[1]();
        runTestMtds[2]();
    end   
     function runtTests1()
        runTestMtds runTestMethod[];
        runTestMtds.appendElement(EBoolean003.runTestConversions02);
        runTestMtds.appendElement(EBoolean003.runTestConversions03);
        runTestMtds[1]();
        runTestMtds[2]();
    end
end
delegate runTestMethod()    
end
===================
package explore;
library EBoolean003 {}
    function runTestConversions02()
    	syslib.writestdout("runTestConversions02");
    end
    function runTestConversions03()
    	syslib.writestdout("runTestConversions03");
    end
End
==============
package explore;
program driver type BasicProgram {}	
	use tester;
	function main()
		tester.runtTests1();
		tester.runtTests2();
	end	
end
Comment 5 Paul Harmon CLA 2011-10-25 11:17:30 EDT
I disagree with making this a validation error, which is just as well, since generation seems to have been modified so that the original coding style now produces java that compiles. I have tested this with a variety of ways of initializing the array of delegates and all cases work fine. Here is my testcase:

package pkg1;

library lib2 {}

	del1 runTestMethod = f1;
	del2 runTestMethod = f2;
	
    function runTests()
        runTestMtds1 runTestMethod[] = [f1, f2];
        runTestMtds2 runTestMethod[] = [del1, del2];
    end
    function runtTests2()
        // ok
        runTestMtds runTestMethod?[] = new runTestMethod?[2];
        runTestMtds[1] = f1;
        runTestMtds[2] = f2;
        runTestMtds[1] = del1;
        runTestMtds[2] = del2;
    end
    
    function runtTest3()
         runTestMtds runTestMethod[];
         runTestMtds.appendElement(f1);
         runTestMtds.appendelement(f2);
         runTestMtds.appendElement(del1);
         runTestMtds.appendelement(del2);
    end
    
    function runTests4()
    	runTestMtds runTestMethod[] {f1, f2, del1, del2};
    	
    end
    
    function f1()
    end
    function f2()
    end
end

delegate runTestMethod()    
end
Comment 6 Kathy Carroll CLA 2011-10-27 17:12:54 EDT
verified 20111027_1153 & closed