[Laszlo-dev] For Review: Change 20081021-dda-p Summary: Add return type declarations to SWF9

Donald Anderson dda at ddanderson.com
Thu Oct 23 14:34:40 PDT 2008


On Oct 22, 2008, at 1:10 PM, P T Withington wrote:

> On 2008-10-21, at 17:19EDT, Donald Anderson wrote:
>
>> On Oct 21, 2008, at 2:33 PM, P T Withington wrote:
>>
>>> On 2008-10-21, at 13:57EDT, Donald Anderson wrote:
>>>
>>>>
>>>> On Oct 21, 2008, at 1:01 PM, P T Withington wrote:
>>>>
>>>>> Great stuff!
>>>>>
>>>>> Comments:
>>>>>
>>>>> 1) Our idiom for undefined is `void 0`, because of (http://tinyurl.com/2z3q2o 
>>>>> ),
>>>>
>>>> On an existing line with 'return void(0);'  , I got a flex error  
>>>> about mismatching type.
>>>
>>> There are surely plenty of places in our code where we use the  
>>> idiom `void 0` to mean undefined, so the problem must lie  
>>> elsewhere.  `undefined` may be undefined in as3, but it is not in  
>>> js1, so we can't rely on that.
>>>
>>> `void` is a unary prefix operator that is defined to evaluate its  
>>> operand and return the undefined value.  If Flex is whining about  
>>> that, I'd say that's a Flex bug.
>>>
>>> The parens are not necessary because `void` is an operator not a  
>>> function and 0 and (0) are equivalent expressions.  I used 0 as  
>>> the expression as a nano-optimization (from knowing the byte-codes  
>>> that get generated).
>>>
>>
>> FWIW, here's the error I get if I leave return void(0) in this  
>> function:
>>
>> [/tmp/lzswf9/lzgen49569/LzReplicationManager.as: 344] data/ 
>> LzReplicationManager.lzs: 485: Error: Implicit coercion of a value  
>> of type void to an unrelated type LzReplicationManager.
>
> Interesting.  So class types are 'nullable' but not  
> 'undefinedable'.  Sounds like you need to say `null` instead of  
> `void 0`.  If we have code that depends on distinguishing between  
> the two, our code sucks.


I 'upgraded' all the return values that I inserted in LzDatapointer from
    return undefined;
to:
    return false;   // for Boolean types
    return NaN;   // for int types  (actually this applies to other  
files, not LzDatapointer)
    return (0 cast ClassName)  // for other types

and I got errors in swf8 smokecheck:

   Tests: 873 Failures: 1 Errors: 0
   TestFailure:  >>> testBadDP failed: Undefined:  expected 'undefined  
value' got 0

Some of  these return types were String, and thinking that those might  
return null by default,
I changed all the String return types to
     return null;

Then the error was:

   Tests: 873 Failures: 1 Errors: 0
   TestFailure:  >>> testBadDP failed: Undefined:  expected 'undefined  
value' got null

So at least for routines that return String, where they didn't return  
a value before,
we must return 'undefined' in order for smokecheck to pass.

I suppose an alternative is:
   if ($swf8) {
      return undefined;
   }
   else {
      return void 0;
   }

Yuck.  I'm hoping there will be a somewhat unified approach to fixing  
the dozens of
return values, this is getting painful.  Or is this a case where  
smokecheck is broken,
and I should file a Jira on that?

- Don

--

Don Anderson
Java/C/C++, Berkeley DB, systems consultant

voice: 617-547-7881
email: dda at ddanderson.com
www: http://www.ddanderson.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openlaszlo.org/pipermail/laszlo-dev/attachments/20081023/b1300933/attachment-0001.html


More information about the Laszlo-dev mailing list