cryptool-org/cryptobrief

Strange things happen when multiple arrays are declared in a comma-separated list

Opened this issue · 0 comments

program calculate{

	function foo() : Integer[] {
		a, b : Integer[];
		a := new Integer[3];
		for i = 0 to #a -1 {
			a[i] := 1;
		}
		
		return a;
	}
	
	procedure print_two_arrays(firstArray, secondArray : Integer[]) {
		println(firstArray);
		println(secondArray);
	}
	
	procedure bar() {
		s, t : Integer[];
		
		s := {1,2,3};
		t := foo();
		
		print_two_arrays(s, foo());    // this prints : "null \n {1,1,1}"
		print_two_arrays(s, t);          // this prints : "{1,2,3} \n {1,1,1}"
	}
	
	bar();
}

Expected would be "{1,2,3} \n {1,1,1}" in both cases.
This does NOT occur, when "foo()" is written as follows:

function foo() : Integer[] {
	a : Integer[];
	b : Integer[];
        a := new Integer[3];
	for i = 0 to #a -1 {
		a[i] := 1;
	}
		
	return a;
}