The following code is expected to compile, but does not on the current Shadow compiler.
The signature of ReadOnlyList<T>:create() is create(List<T>).
The compiler should cast the list to a List<T> silently, but does not, and instead throws:
java.lang.IllegalArgumentException: Check of operand shadow:utility@ArrayList<int> list of type shadow:utility@ArrayList<int> and shadow:utility@List<T> of type shadow:utility@List<T> couldn't be resolved!
The code that caused this issue is:
public main(String[] args) => ()
{
var list = ArrayList<int>:create();
// PROBLEM HERE
var readonlyList = ReadOnlyList<int>:create(list);
list.add(5);
list.add(7);
foreach(int value in readonlyList) {
Console.printLine(value);
}
}
We could however, fix this problem by using:
var readonlyList = ReadOnlyList<int>:create(cast<List<int>>(list)); and the program executes correctly.
The following code is expected to compile, but does not on the current Shadow compiler. The signature of
ReadOnlyList<T>:create()
iscreate(List<T>)
. The compiler should cast the list to aList<T>
silently, but does not, and instead throws:java.lang.IllegalArgumentException: Check of operand shadow:utility@ArrayList<int> list of type shadow:utility@ArrayList<int> and shadow:utility@List<T> of type shadow:utility@List<T> couldn't be resolved!
The code that caused this issue is:
We could however, fix this problem by using:
var readonlyList = ReadOnlyList<int>:create(cast<List<int>>(list));
and the program executes correctly.