Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a property ::= does not work for rvalue covers because a pointer is expected #940

Open
marcusnaslund opened this issue Nov 4, 2015 · 7 comments

Comments

@marcusnaslund
Copy link
Contributor

For example:

// myAttribute in MyCover is calculated using ::=

// Not working
result = myCovers[i] myAttribute

// Working
myCover := myCovers[i] // Convert rvalue to lvalue
result = myCover myAttribute

It appears properties have similar limitations in C# as well, so I don't know what the plan is here.

At least, the error should be explained by rock instead of failing in the C compiler.

@alexnask
Copy link
Collaborator

alexnask commented Nov 4, 2015

I'm taking a look at this right now (I'm assuming myCovers is an ArrayList of some cover) but what was said in the ooc-kean issue looks accurate.

@alexnask
Copy link
Collaborator

alexnask commented Nov 4, 2015

It looks like we could generate some code that would handle it, I will reopen the issue if we indeed can.

@marcusnaslund
Copy link
Contributor Author

Let me take a closer look and get back to you on this.

@alexnask
Copy link
Collaborator

alexnask commented Nov 4, 2015

I can reproduce this with an ooc array:

import structs/ArrayList

Foo: cover {
    calculated ::= 42
}

arr := Foo[1] new()
foo: Foo
arr[0] = foo

arr[0] calculated toString() println()

Using an ArrayList seems to work on my end.

If you could post a testcase I would be grateful.

@davidhesselbom
Copy link
Contributor

@marcusnaslund , just a reminder...

@davidhesselbom
Copy link
Contributor

import structs/ArrayList

Foos: class {
    init: func
    operator [] (index: Int) -> Foo {
        Foo new()
    }
}
Foo: cover {
    bar: Int
    init: func@
}

foos := Foos new()
list := ArrayList<Int> new()
list add(foos[0] bar)

This fails to build with the error

lvalue required as unary ‘&’ operand
list add(foos[0] bar)

However, any of the 3 following changes will independently fix the build error:

  • Breaking up the last line into two lines:
foo := foos[0]
list add(foo bar)
  • Changing bar into a property
    bar: Int { get set }
  • Making Foo a class instead of a cover:
Foo: class {
    bar: Int
    init: func
}

I don't know if this is specifically what @marcusnaslund had a problem with, but perhaps it's related?

@marcusnaslund
Copy link
Contributor Author

Oh, thank you very much @davidhesselbom - then we are able to reproduce this issue both with arrays and ArrayList. I'm reponening this.

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

No branches or pull requests

3 participants