TeamShadow / shadow

Reference compiler for the Shadow programming language.
http://shadow-language.org/
Apache License 2.0
12 stars 8 forks source link

Generic Interfaces - Compiler Level #55

Closed claude-abounegm closed 7 years ago

claude-abounegm commented 7 years ago

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.

bwittman commented 7 years ago

Fixed by #66 (if not earlier).