cx-language / cx

C* is a hybrid low-level/high-level systems programming language focused on performance and productivity.
https://cx-language.github.io/
MIT License
130 stars 9 forks source link

cannot call mutating function with immutable 'this' #5

Closed Coolnesss closed 7 years ago

Coolnesss commented 7 years ago

I get

./src/Vector.delta:17:24: error: cannot call mutating function with immutable 'this'
      array.append(*arr[e]);
                       ^

for

init(arr : Vector<T>&) {
    this.array = Array<T>();

    for (e in 0..array.size()) {
      array.append(*arr[e]);
    }
  }

Even though this should be mutable in the constructor

emlai commented 7 years ago

Thanks! The error message refers to the [] operator of your Vector class, not the append() method, so it's actually correct. But I agree that the error message is a bit misleading here. 0eb01030b78a5a644b8551fcca080c67db6ecbb7 improves it so it's now:

./src/Vector.delta:17:24: error: cannot call mutating function 'Vector.[]' on immutable receiver
      array.append(*arr[e]);
                       ^