ooc-lang / rock

:ocean: self-hosted ooc compiler that generates c99
http://ooc-lang.org/
MIT License
404 stars 40 forks source link

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

Open marcusnaslund opened 8 years ago

marcusnaslund commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

marcusnaslund commented 8 years ago

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

alexnask commented 8 years ago

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 commented 8 years ago

@marcusnaslund , just a reminder...

davidhesselbom commented 8 years ago
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:

foo := foos[0]
list add(foo bar)
    bar: Int { get set }
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 commented 8 years ago

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