From 9a12d6bc624f3353a7a97c3a6c3d54df64c5bb28 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Sat, 16 Aug 2014 01:23:46 +0200 Subject: [PATCH] Closes #782 --- source/rock/middle/PropertyDecl.ooc | 16 ++++++++------ .../{extend_pdfe.ooc => extend-pdfe.ooc} | 0 ...d_properties.ooc => extend-properties.ooc} | 0 test/compiler/properties/pdfe-cover.ooc | 21 +++++++++++++++++++ 4 files changed, 31 insertions(+), 6 deletions(-) rename test/compiler/properties/{extend_pdfe.ooc => extend-pdfe.ooc} (100%) rename test/compiler/properties/{extend_properties.ooc => extend-properties.ooc} (100%) create mode 100644 test/compiler/properties/pdfe-cover.ooc diff --git a/source/rock/middle/PropertyDecl.ooc b/source/rock/middle/PropertyDecl.ooc index 247a9e1b..c6e53ed6 100644 --- a/source/rock/middle/PropertyDecl.ooc +++ b/source/rock/middle/PropertyDecl.ooc @@ -75,6 +75,16 @@ PropertyDecl: class extends VariableDecl { } cls = node as ClassDecl + // setup getter + if(getter != null) { + // are we a cover? if yes, use func@ + if(cls instanceOf?(CoverDecl)) { + if(cls as CoverDecl fromType == null || !cls as CoverDecl fromType isPointer()) { + getter isThisRef = true + } + } + } + { response := super(trail, res) if (!response ok()) { @@ -128,12 +138,6 @@ PropertyDecl: class extends VariableDecl { getter setName(getGetterName()) .setReturnType(type) cls addFunction(getter) - // are we a cover? if yes, use func@ - if(cls instanceOf?(CoverDecl)) { - if(cls as CoverDecl fromType == null || !cls as CoverDecl fromType isPointer()) { - getter isThisRef = true - } - } // static property -> static getter if(isStatic()) { getter setStatic(true) diff --git a/test/compiler/properties/extend_pdfe.ooc b/test/compiler/properties/extend-pdfe.ooc similarity index 100% rename from test/compiler/properties/extend_pdfe.ooc rename to test/compiler/properties/extend-pdfe.ooc diff --git a/test/compiler/properties/extend_properties.ooc b/test/compiler/properties/extend-properties.ooc similarity index 100% rename from test/compiler/properties/extend_properties.ooc rename to test/compiler/properties/extend-properties.ooc diff --git a/test/compiler/properties/pdfe-cover.ooc b/test/compiler/properties/pdfe-cover.ooc new file mode 100644 index 00000000..f669ea65 --- /dev/null +++ b/test/compiler/properties/pdfe-cover.ooc @@ -0,0 +1,21 @@ + +import math + +// Does not build +Point: cover { + x, y: Float + norm ::= (this x pow(2.0f) + this y pow(2.0f)) sqrt() + normToo : Float { get { (this x pow(2.0f) + this y pow(2.0f)) sqrt() } } +} + +main: func { + p := (2, 2) as Point + n1 := p norm + n2 := p normToo + if (n1 != n2) { + "Fail: expected n1 == n2, but got %f != %f" printfln(n1, n2) + exit(1) + } + + "Pass" println() +}