diff --git a/source/rock/middle/ArrayAccess.ooc b/source/rock/middle/ArrayAccess.ooc index d585261a..4f08c6f7 100644 --- a/source/rock/middle/ArrayAccess.ooc +++ b/source/rock/middle/ArrayAccess.ooc @@ -469,7 +469,20 @@ ArrayAccess: class extends Expression { b toString() } - isReferencable: func -> Bool { true } + isReferencable: func -> Bool { + if (array getType()) { + if (array getType() instanceOf?(ArrayType)) { + // ArrayTypes with expressions are actually C arrays, which are referencable (while ooc arrays are not) + arrayType := array getType() as ArrayType + + return arrayType expr != null + } else if (array getType() instanceOf?(PointerType)) { + return true + } + } + + array isReferencable() + } replace: func (oldie, kiddo: Node) -> Bool { match oldie { diff --git a/source/rock/middle/VariableAccess.ooc b/source/rock/middle/VariableAccess.ooc index 2cb6d4fd..d5751e17 100644 --- a/source/rock/middle/VariableAccess.ooc +++ b/source/rock/middle/VariableAccess.ooc @@ -818,8 +818,15 @@ VariableAccess: class extends Expression { expr ? (expr toString() + " " + prettyName) : prettyName } - isReferencable: func -> Bool { ref && ref instanceOf?(VariableDecl) && - (ref as VariableDecl isExtern() && ref as VariableDecl isConst()) ? false : true } + isReferencable: func -> Bool { + if (ref && ref instanceOf?(VariableDecl)) { + if (ref as VariableDecl isExtern() && ref as VariableDecl isConst()) { + return false + } + } + + true + } replace: func (oldie, kiddo: Node) -> Bool { match oldie { diff --git a/test/compiler/arrays/array-retrieve-calculated-property.ooc b/test/compiler/arrays/array-retrieve-calculated-property.ooc new file mode 100644 index 00000000..18b4cd86 --- /dev/null +++ b/test/compiler/arrays/array-retrieve-calculated-property.ooc @@ -0,0 +1,11 @@ +Foo: cover { + calculated ::= 42 +} + +describe("should be able to directly use a calculated property of a cover stored in an ooc array", || + arr := Foo[1] new() + foo: Foo + arr[0] = foo + + expect(42, arr[0] calculated) +) diff --git a/test/compiler/generics/calculated-cover-property-operator-argument.ooc b/test/compiler/generics/calculated-cover-property-operator-argument.ooc new file mode 100644 index 00000000..286ed1a1 --- /dev/null +++ b/test/compiler/generics/calculated-cover-property-operator-argument.ooc @@ -0,0 +1,22 @@ +import structs/ArrayList + +Foos: class { + init: func + operator [] (index: Int) -> Foo { + Foo new(42) + } +} + +Foo: cover { + bar: Int + init: func@ (=bar) +} + +describe("we should be able to call a generic function on a calculated property of a cover returned by an operator call", || + foos := Foos new() + list := ArrayList new() + + list add(foos[0] bar) + + expect(42, list last()) +)