Enforcing return value types

# Nathan de Vries (18 years ago)

What's the expected behaviour for a function returning a value, of which the type is contrary to the type defined in the function declaration?

For example:

var func:Function = function():int {
    return "This is not an int";
}
typeof(func()); // string

Is this expected behaviour? Here's some similar Actionscript 3 code:

package {
    class ReturnTest {
        public function ReturnTest():void {
            returnInt();
        }
        private function returnInt():int {
            return "String instead";
        }
    }
}

...which produces the following compile-time error:

Implicit coercion of a value of type String to an unrelated type 
int.

,

-- Nathan de Vries

PS: Fantastic work with the Linux build of the reference implementation. I'm working my way through the overview documentation, and will probably have a poke at the SML when I'm feeling more game :).

# Lars T Hansen (18 years ago)

I'm guessing you're just experiencing the effects of bugs.ecmascript.org/ticket/285. The correct behavior is a run-time error in standard mode; compile-time error in strict mode.

# Nathan de Vries (18 years ago)

On Mon, 2007-11-12 at 23:50 -0800, Lars T Hansen wrote:

I'm guessing you're just experiencing the effects of bugs.ecmascript.org/ticket/285. The correct behavior is a run-time error in standard mode; compile-time error in strict mode.

Ah, so it is. I'll assume the implementers will know that the scope of the ticket is greater than that of functions with void return value types defined.

,

-- Nathan de Vries