From 6ddc1b2f71a3cecc1d125966e13ca1c523e02e21 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Fri, 11 Mar 2016 17:14:33 +0200 Subject: [PATCH 1/5] Stricter and more correct referencability checks. Fixes some issues with passing calling operators and properties on cover types --- source/rock/middle/ArrayAccess.ooc | 13 ++++++++++++- source/rock/middle/VariableAccess.ooc | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/source/rock/middle/ArrayAccess.ooc b/source/rock/middle/ArrayAccess.ooc index d585261a..daa2ca6e 100644 --- a/source/rock/middle/ArrayAccess.ooc +++ b/source/rock/middle/ArrayAccess.ooc @@ -469,7 +469,18 @@ ArrayAccess: class extends Expression { b toString() } - isReferencable: func -> Bool { true } + isReferencable: func -> Bool { + if (array getType()) { + if (array getType() instanceOf?(ArrayType)) { + // ooc arrays are not referencable + return false + } 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..5a610ace 100644 --- a/source/rock/middle/VariableAccess.ooc +++ b/source/rock/middle/VariableAccess.ooc @@ -818,8 +818,19 @@ 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 + } + } + + if (expr) { + return expr isReferencable() + } + + true + } replace: func (oldie, kiddo: Node) -> Bool { match oldie { From 9f1cba053bc0517b95a939bf8f30502963f00d43 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Fri, 11 Mar 2016 17:38:06 +0200 Subject: [PATCH 2/5] Added two very specific tests --- .../array-retrieve-calculated-property.ooc | 11 ++++++++++ ...lated-cover-property-operator-argument.ooc | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/compiler/arrays/array-retrieve-calculated-property.ooc create mode 100644 test/compiler/generics/calculated-cover-property-operator-argument.ooc 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..aa6c287b --- /dev/null +++ b/test/compiler/arrays/array-retrieve-calculated-property.ooc @@ -0,0 +1,11 @@ +Foo: cover { + calculated ::= 42 +} + +desribe("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()) +) From b8c85800b710be8fcf8d44dcca8246d4bddee5a9 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Fri, 11 Mar 2016 17:44:09 +0200 Subject: [PATCH 3/5] Fixed type causing test to fail --- test/compiler/arrays/array-retrieve-calculated-property.ooc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/compiler/arrays/array-retrieve-calculated-property.ooc b/test/compiler/arrays/array-retrieve-calculated-property.ooc index aa6c287b..18b4cd86 100644 --- a/test/compiler/arrays/array-retrieve-calculated-property.ooc +++ b/test/compiler/arrays/array-retrieve-calculated-property.ooc @@ -2,7 +2,7 @@ Foo: cover { calculated ::= 42 } -desribe("should be able to directly use a calculated property of a cover stored in an ooc array", || +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 From 0733069186c9ca71e46c7fe5891041a829ebb669 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Mon, 25 Apr 2016 16:53:29 +0300 Subject: [PATCH 4/5] Not all ArrayTypes are ooc arrays, correct array access referencability check --- source/rock/middle/ArrayAccess.ooc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/rock/middle/ArrayAccess.ooc b/source/rock/middle/ArrayAccess.ooc index daa2ca6e..4f08c6f7 100644 --- a/source/rock/middle/ArrayAccess.ooc +++ b/source/rock/middle/ArrayAccess.ooc @@ -472,8 +472,10 @@ ArrayAccess: class extends Expression { isReferencable: func -> Bool { if (array getType()) { if (array getType() instanceOf?(ArrayType)) { - // ooc arrays are not referencable - return false + // 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 } From 3141824362570409c22a87a89a70dc9005a2c833 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Sun, 29 May 2016 17:23:44 +0300 Subject: [PATCH 5/5] Variable accesses are always referencable except for C defines --- source/rock/middle/VariableAccess.ooc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/rock/middle/VariableAccess.ooc b/source/rock/middle/VariableAccess.ooc index 5a610ace..d5751e17 100644 --- a/source/rock/middle/VariableAccess.ooc +++ b/source/rock/middle/VariableAccess.ooc @@ -825,10 +825,6 @@ VariableAccess: class extends Expression { } } - if (expr) { - return expr isReferencable() - } - true }