parapluu / encore

The Encore compiler.
BSD 3-Clause "New" or "Revised" License
43 stars 26 forks source link

Parametric polymorphism and array types seem to be broken #236

Closed TobiasWrigstad closed 8 years ago

TobiasWrigstad commented 8 years ago

It seems an additional level of array is added.

class Main
  def main() : void
    ()

passive class Bug<t>
  def here() : Bug<[t]>
    new Bug<[t]>

generates

Type 'Bug<[[t]]>' does not match expected type 'Bug<[t]>'
In expression:
  new Bug<[t]>
In method 'here' of type 'Bug<[t]>'
In class 'Bug<t>'
EliasC commented 8 years ago

I can look at this while fixing #234!

TobiasWrigstad commented 8 years ago

Thanks!

albertnetymk commented 8 years ago

I am a bit confused. I thought the error message is expected, for we are substituting t with [t] in the new statement, and the return type becomes [[t]] accordingly.

EliasC commented 8 years ago

Let's make a more concrete example:

class List<t>
  def eachElementAsAnArray() : List<[t]>
    let l = new List<[t]> in
      ... -- some expression that ends in l

Would you agree that this code should compile?

albertnetymk commented 8 years ago

Could you provide complete snippet?

EliasC commented 8 years ago
passive class Container<t>
  content : t
  def containerWithArray() : Container<[t]>
    let c = new Container<[t]> in {
      c.content = [this.content];
      c
    }

class Main
  def main() : void
    let c1 = new Container<int> in{
      c1.content = 42;
      let c2 = c1.containerWithArray() in
        assertTrue(c2.content[0] == c1.content);
      print "passed"
    }
albertnetymk commented 8 years ago

OK, clearly now. Thanks.

EliasC commented 8 years ago

Fixed as of 3619b53ae4a730f8a42e702641c0a87f4431f49b.