Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Ark doesn't like it when you use the indexing operator on call expressions #719

Open
felixangell opened this issue Mar 2, 2016 · 6 comments

Comments

@felixangell
Copy link
Member

func foo() -> ^u8 { ... }
...
foo()[0]; // error!
@kiljacken
Copy link
Member

In the future, could you include the error log?

On Wed, Mar 2, 2016, 03:43 Felix Angell [email protected] wrote:

func foo() -> ^u8 { ... }
...
foo()[0]; // error!


Reply to this email directly or view it on GitHub
#719.

@felixangell
Copy link
Member Author

Oop, sorry. This was just a quick issue at 5am before I went to sleep 😉

@kiljacken
Copy link
Member

Happens due to most of our access-expressions only working on other access expressions. The fix will be to not force this in the constructor, I think, and then just leave the work to the type checker.

kiljacken added a commit that referenced this issue Mar 7, 2016
kiljacken added a commit that referenced this issue Mar 8, 2016
@kiljacken
Copy link
Member

A bit more cursory coding shows me the underlying issue. We currently only allow struct access/array indexing on access expressions. This is due to mutability only being handled for access expressions, and we wouldn't want people to write to a immutable array/struct.

So if we want to fix this we need to move mutability completely into the type system, which is a fair bit of work.

@MovingtoMars
Copy link
Member

Eh, I don't think we need to go that far. The result of a call expression should always be mutable. It only becomes immutable when we bind it to an immutable variable. t := do();

@kiljacken
Copy link
Member

The main concern is the case where you return an array. We have no other way to specify that the backing array is immutable, and we need a way to express this. Take this example:

// immutable
data := []int{0, 1, 2, 3, 4};

func ohBoy() -> []int {
    return data;
}

func main() -> int {
    mut array := ohBoy(); // and now we can theoretically modify data, even though it is immutable
    array[2] = 42; // no errors here (well, probably from llvm, but not from us)
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants