You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Justin Mclean <ju...@classsoftware.com> on 2012/07/04 03:57:35 UTC

Odd undefined property via reference to static type compilation error

Hi,

Anyone have an idea why this:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx">
	<fx:Script>
		<![CDATA[
			protected var minimum:Number = this.minHeight;
		]]>
	</fx:Script>
</s:Application>

Gives:
1119: Access of possibly undefined property minHeight through a reference with static type Class.

But if you remove "this." it compiles without error:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx">
	<fx:Script>
		<![CDATA[
			protected var minimum:Number = minHeight;
		]]>
	</fx:Script>
</s:Application>

Thanks,
Justin


Re: Odd undefined property via reference to static type compilation error

Posted by Harbs <ha...@gmail.com>.
Weird stuff. I would not have thought that private and protected would be different here.

Harbs

On Jul 9, 2012, at 10:14 PM, Desai, Ashish S wrote:

> Different decompiler can give different results. Somehow what you gave in source happens to work. Even this works
> 
> private static var myvarfirst:String = "testing";
> 
> private var myVar:String = this.myvarfirst;
> 
> It allows assigning static values in non-static way and non-static values in static way. Java allows both ways below:
> 
>    private String s3 = "jpm";
>    private String s2 =s3;
> 
>    private static String s3 = "jpm";
>    private String s2 = this.s3;
> 
> Thanks,
> Ashish
> 
> 
> -----Original Message-----
> From: omuppi1@gmail.com [mailto:omuppi1@gmail.com] On Behalf Of Om
> Sent: Monday, July 09, 2012 3:05 PM
> To: flex-dev@incubator.apache.org
> Subject: Re: Odd undefined property via reference to static type compilation error
> 
> FWIW, I ran the compiled code through a decompiler and this is how the same code gets converted as:
> 
> *Source*:
> 
> package
> {
>    public class A
>    {
> 
>        public var minHeight:Number = 9;
>        public var minHeight2:Number = minHeight;
> 
>    }
> }
> 
> *After decompilation*:
> 
> package
> {
>        public class A
>        {
>                public function A()
>                {
>                        this.minHeight2 = this.minHeight;
>                }
>                public var minHeight2:Number;
>                public var minHeight:Number = 9;
>        }
> }
> 
> 
> Next, I tried this (compiles fine):
> 
> *Source:*
> 
> package
> {
>    public class A
>    {
> 
>        public var minHeight:Number = 9;
>        public var minHeight2:Number = this["minHeight"];
> 
>    }
> }
> 
> *After decompilation:*
> 
> package
> {
>        public class A
>        {
>                public function A()
>                {
>                        this.minHeight2 = this['minHeight'];
>                }
>                public var minHeight2:Number;
>                public var minHeight:Number = 9;
>        }
> }
> 
> 
> Not sure if we learned something here, but it just makes it more interesting :-)
> 
> Om
> 
> 
> On Mon, Jul 9, 2012 at 11:34 AM, Ryan Frishberg <fr...@gmail.com> wrote:
> 
>> In ActionScript, it looks like this doesn't work:
>> 
>> class A
>> {
>> 
>> public var minHeight:Number = 9;
>> 
>> protected var minHeight2:Number = this.minHeight;
>> 
>> }
>> 
>> Someone who knows ActionScript in more detail can probably explain why 
>> the compilter/runtime can't figure out what "this" should refer to 
>> when initializing class properties.
>> 
>> -Ryan
>> 
>> On Wed, Jul 4, 2012 at 5:53 PM, Justin Mclean 
>> <justin@classsoftware.com
>>> wrote:
>> 
>>> Hi,
>>> 
>>>> BTW, is this an issue in Adobe Flex 4.6 as well?
>>> Yep issue with both 4.6 and 4.8 and couldn't find an existing JIRA 
>>> report for it.
>>> 
>>> Justin
>> 
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.


RE: Odd undefined property via reference to static type compilation error

Posted by "Desai, Ashish S" <as...@jpmorgan.com>.
Different decompiler can give different results. Somehow what you gave in source happens to work. Even this works

private static var myvarfirst:String = "testing";

private var myVar:String = this.myvarfirst;

It allows assigning static values in non-static way and non-static values in static way. Java allows both ways below:

    private String s3 = "jpm";
    private String s2 =s3;

    private static String s3 = "jpm";
    private String s2 = this.s3;

Thanks,
Ashish


-----Original Message-----
From: omuppi1@gmail.com [mailto:omuppi1@gmail.com] On Behalf Of Om
Sent: Monday, July 09, 2012 3:05 PM
To: flex-dev@incubator.apache.org
Subject: Re: Odd undefined property via reference to static type compilation error

FWIW, I ran the compiled code through a decompiler and this is how the same code gets converted as:

*Source*:

package
{
    public class A
    {

        public var minHeight:Number = 9;
        public var minHeight2:Number = minHeight;

    }
}

*After decompilation*:

package
{
        public class A
        {
                public function A()
                {
                        this.minHeight2 = this.minHeight;
                }
                public var minHeight2:Number;
                public var minHeight:Number = 9;
        }
}


Next, I tried this (compiles fine):

*Source:*

package
{
    public class A
    {

        public var minHeight:Number = 9;
        public var minHeight2:Number = this["minHeight"];

    }
}

*After decompilation:*

package
{
        public class A
        {
                public function A()
                {
                        this.minHeight2 = this['minHeight'];
                }
                public var minHeight2:Number;
                public var minHeight:Number = 9;
        }
}


Not sure if we learned something here, but it just makes it more interesting :-)

Om


On Mon, Jul 9, 2012 at 11:34 AM, Ryan Frishberg <fr...@gmail.com> wrote:

> In ActionScript, it looks like this doesn't work:
>
> class A
> {
>
> public var minHeight:Number = 9;
>
> protected var minHeight2:Number = this.minHeight;
>
> }
>
> Someone who knows ActionScript in more detail can probably explain why 
> the compilter/runtime can't figure out what "this" should refer to 
> when initializing class properties.
>
> -Ryan
>
> On Wed, Jul 4, 2012 at 5:53 PM, Justin Mclean 
> <justin@classsoftware.com
> >wrote:
>
> > Hi,
> >
> > > BTW, is this an issue in Adobe Flex 4.6 as well?
> > Yep issue with both 4.6 and 4.8 and couldn't find an existing JIRA 
> > report for it.
> >
> > Justin
>
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

Re: Odd undefined property via reference to static type compilation error

Posted by Om <bi...@gmail.com>.
FWIW, I ran the compiled code through a decompiler and this is how the same
code gets converted as:

*Source*:

package
{
    public class A
    {

        public var minHeight:Number = 9;
        public var minHeight2:Number = minHeight;

    }
}

*After decompilation*:

package
{
        public class A
        {
                public function A()
                {
                        this.minHeight2 = this.minHeight;
                }
                public var minHeight2:Number;
                public var minHeight:Number = 9;
        }
}


Next, I tried this (compiles fine):

*Source:*

package
{
    public class A
    {

        public var minHeight:Number = 9;
        public var minHeight2:Number = this["minHeight"];

    }
}

*After decompilation:*

package
{
        public class A
        {
                public function A()
                {
                        this.minHeight2 = this['minHeight'];
                }
                public var minHeight2:Number;
                public var minHeight:Number = 9;
        }
}


Not sure if we learned something here, but it just makes it more
interesting :-)

Om


On Mon, Jul 9, 2012 at 11:34 AM, Ryan Frishberg <fr...@gmail.com> wrote:

> In ActionScript, it looks like this doesn't work:
>
> class A
> {
>
> public var minHeight:Number = 9;
>
> protected var minHeight2:Number = this.minHeight;
>
> }
>
> Someone who knows ActionScript in more detail can probably explain why the
> compilter/runtime can't figure out what "this" should refer to when
> initializing class properties.
>
> -Ryan
>
> On Wed, Jul 4, 2012 at 5:53 PM, Justin Mclean <justin@classsoftware.com
> >wrote:
>
> > Hi,
> >
> > > BTW, is this an issue in Adobe Flex 4.6 as well?
> > Yep issue with both 4.6 and 4.8 and couldn't find an existing JIRA report
> > for it.
> >
> > Justin
>

Re: Odd undefined property via reference to static type compilation error

Posted by Jeff Dyer <je...@acm.org>.
Yes, that is because strict mode punts on index expressions, because it
doesn't in general know the string value of the index. That'll be
workaround #3.

Jeff

On Mon, Jul 9, 2012 at 2:53 PM, Om <bi...@gmail.com> wrote:

> On Mon, Jul 9, 2012 at 2:40 PM, Jeff Dyer <je...@acm.org> wrote:
>
> > This is probably a compiler bug, if not a language bug. Instance
> > initializers were ill defined in AS3. In the draft ES4 spec we pinned
> them
> > down to be scoped to the class static scope, so references to 'this' or
> > instance variables would not be resolved in instance initializers. That
> > said, AS3 did allow them with some what vague initialization semantics.
> The
> > bug here is that 'this' is not allowed in instance initializers in strict
> > mode.
> >
> > There are two workarounds: 1/erase the 'this.' prefix; 2/turn off strict
> > mode.
> >
> > Jeff
> >
> >
> >
> Thanks for explanation, Jeff.  Interestingly, this["minHeight"] seems to
> work fine in the instance initializer, even in strict mode.
>
>
> >
> > On Mon, Jul 9, 2012 at 11:34 AM, Ryan Frishberg <fr...@gmail.com>
> wrote:
> >
> > > In ActionScript, it looks like this doesn't work:
> > >
> > > class A
> > > {
> > >
> > > public var minHeight:Number = 9;
> > >
> > > protected var minHeight2:Number = this.minHeight;
> > >
> > > }
> > >
> > > Someone who knows ActionScript in more detail can probably explain why
> > the
> > > compilter/runtime can't figure out what "this" should refer to when
> > > initializing class properties.
> > >
> > > -Ryan
> > >
> > > On Wed, Jul 4, 2012 at 5:53 PM, Justin Mclean <
> justin@classsoftware.com
> > > >wrote:
> > >
> > > > Hi,
> > > >
> > > > > BTW, is this an issue in Adobe Flex 4.6 as well?
> > > > Yep issue with both 4.6 and 4.8 and couldn't find an existing JIRA
> > report
> > > > for it.
> > > >
> > > > Justin
> > >
> >
>

Re: Odd undefined property via reference to static type compilation error

Posted by Om <bi...@gmail.com>.
On Mon, Jul 9, 2012 at 2:40 PM, Jeff Dyer <je...@acm.org> wrote:

> This is probably a compiler bug, if not a language bug. Instance
> initializers were ill defined in AS3. In the draft ES4 spec we pinned them
> down to be scoped to the class static scope, so references to 'this' or
> instance variables would not be resolved in instance initializers. That
> said, AS3 did allow them with some what vague initialization semantics. The
> bug here is that 'this' is not allowed in instance initializers in strict
> mode.
>
> There are two workarounds: 1/erase the 'this.' prefix; 2/turn off strict
> mode.
>
> Jeff
>
>
>
Thanks for explanation, Jeff.  Interestingly, this["minHeight"] seems to
work fine in the instance initializer, even in strict mode.


>
> On Mon, Jul 9, 2012 at 11:34 AM, Ryan Frishberg <fr...@gmail.com> wrote:
>
> > In ActionScript, it looks like this doesn't work:
> >
> > class A
> > {
> >
> > public var minHeight:Number = 9;
> >
> > protected var minHeight2:Number = this.minHeight;
> >
> > }
> >
> > Someone who knows ActionScript in more detail can probably explain why
> the
> > compilter/runtime can't figure out what "this" should refer to when
> > initializing class properties.
> >
> > -Ryan
> >
> > On Wed, Jul 4, 2012 at 5:53 PM, Justin Mclean <justin@classsoftware.com
> > >wrote:
> >
> > > Hi,
> > >
> > > > BTW, is this an issue in Adobe Flex 4.6 as well?
> > > Yep issue with both 4.6 and 4.8 and couldn't find an existing JIRA
> report
> > > for it.
> > >
> > > Justin
> >
>

Re: Odd undefined property via reference to static type compilation error

Posted by Jeff Dyer <je...@acm.org>.
This is probably a compiler bug, if not a language bug. Instance
initializers were ill defined in AS3. In the draft ES4 spec we pinned them
down to be scoped to the class static scope, so references to 'this' or
instance variables would not be resolved in instance initializers. That
said, AS3 did allow them with some what vague initialization semantics. The
bug here is that 'this' is not allowed in instance initializers in strict
mode.

There are two workarounds: 1/erase the 'this.' prefix; 2/turn off strict
mode.

Jeff



On Mon, Jul 9, 2012 at 11:34 AM, Ryan Frishberg <fr...@gmail.com> wrote:

> In ActionScript, it looks like this doesn't work:
>
> class A
> {
>
> public var minHeight:Number = 9;
>
> protected var minHeight2:Number = this.minHeight;
>
> }
>
> Someone who knows ActionScript in more detail can probably explain why the
> compilter/runtime can't figure out what "this" should refer to when
> initializing class properties.
>
> -Ryan
>
> On Wed, Jul 4, 2012 at 5:53 PM, Justin Mclean <justin@classsoftware.com
> >wrote:
>
> > Hi,
> >
> > > BTW, is this an issue in Adobe Flex 4.6 as well?
> > Yep issue with both 4.6 and 4.8 and couldn't find an existing JIRA report
> > for it.
> >
> > Justin
>

Re: Odd undefined property via reference to static type compilation error

Posted by Ryan Frishberg <fr...@gmail.com>.
In ActionScript, it looks like this doesn't work:

class A
{

public var minHeight:Number = 9;

protected var minHeight2:Number = this.minHeight;

}

Someone who knows ActionScript in more detail can probably explain why the
compilter/runtime can't figure out what "this" should refer to when
initializing class properties.

-Ryan

On Wed, Jul 4, 2012 at 5:53 PM, Justin Mclean <ju...@classsoftware.com>wrote:

> Hi,
>
> > BTW, is this an issue in Adobe Flex 4.6 as well?
> Yep issue with both 4.6 and 4.8 and couldn't find an existing JIRA report
> for it.
>
> Justin

Re: Odd undefined property via reference to static type compilation error

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> BTW, is this an issue in Adobe Flex 4.6 as well?
Yep issue with both 4.6 and 4.8 and couldn't find an existing JIRA report for it.

Justin

Re: Odd undefined property via reference to static type compilation error

Posted by Alex Harui <ah...@adobe.com>.


On 7/4/12 3:43 AM, "Justin Mclean" <ju...@classsoftware.com> wrote:

> Hi,
> 
>> The generated actionscript should shed some light on the mystery.   Have
>> you taken a look yet?
>  I tired using Flash Builder but it died on me - sigh.
BTW, is this an issue in Adobe Flex 4.6 as well?

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: Odd undefined property via reference to static type compilation error

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> The generated actionscript should shed some light on the mystery.   Have
> you taken a look yet?
 I tired using Flash Builder but it died on me - sigh.

Justin

Re: Odd undefined property via reference to static type compilation error

Posted by OmPrakash Muppirala <om...@gmail.com>.
The generated actionscript should shed some light on the mystery.   Have
you taken a look yet?

Om
On Jul 3, 2012 6:58 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:

> Hi,
>
> Anyone have an idea why this:
> <?xml version="1.0" encoding="utf-8"?>
> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
>                            xmlns:s="library://ns.adobe.com/flex/spark"
>                            xmlns:mx="library://ns.adobe.com/flex/mx">
>         <fx:Script>
>                 <![CDATA[
>                         protected var minimum:Number = this.minHeight;
>                 ]]>
>         </fx:Script>
> </s:Application>
>
> Gives:
> 1119: Access of possibly undefined property minHeight through a reference
> with static type Class.
>
> But if you remove "this." it compiles without error:
> <?xml version="1.0" encoding="utf-8"?>
> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
>                            xmlns:s="library://ns.adobe.com/flex/spark"
>                            xmlns:mx="library://ns.adobe.com/flex/mx">
>         <fx:Script>
>                 <![CDATA[
>                         protected var minimum:Number = minHeight;
>                 ]]>
>         </fx:Script>
> </s:Application>
>
> Thanks,
> Justin
>
>