gauravssnl / skulpt

Automatically exported from code.google.com/p/skulpt
Other
0 stars 0 forks source link

A try block with a return statement that contains a comparison fails #109

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Code you're trying to run:
def test(i):
    f = 3
    try:
        return f == 5
    except ValueError:
        return True

What does "real" Python output?
False

What does Skulpt output?
Unhandled Error: at line 25, column 274: expected expression, got keyword 'case'

Additional information:
Happens at the first case after the try-statement below.

var $scope0 = (function ($modname) {
    var $blk = 0,
        $exc = [],
        $gbl = {}, $loc = $gbl;
    $gbl.__name__ = $modname;
    while (true) {
        switch ($blk) {
        case 0:
            /* --- module entry --- */
            //
            // line 1:
            // def test(Questions):
            // ^
            //
            $scope1.co_name = new Sk.builtins['str']('test');
            $scope1.co_varnames = ['Questions'];
            var $funcobj8 = new Sk.builtins['function']($scope1, $gbl);
            $loc.test = $funcobj8;
            return $loc;
            goog.asserts.fail('unterminated block');
        }
    }
});
var $scope1 = (function $test2$(Questions) {
    var f; /* locals */
    var $blk = 0,
        $exc = [],
        $loc = {}, $gbl = this;
    while (true) {
        switch ($blk) {
        case 0:
            /* --- codeobj entry --- */
            //
            // line 2:
            //  f = 3
            //  ^
            //
            f = 3;
            //
            // line 3:
            //  try:
            //  ^
            //
            $exc.push(1);
            try {
                //
                // line 4:
                //      return f == 5
                //   ^
                //
                var $compareres3 = null;
                var $compare4 = Sk.misceval.richCompareBool(f, 5, 'Eq');
                $compareres3 = $compare4;
                var $jfalse5 = ($compare4 === false || !Sk.misceval.isTrue($compare4));
                if ($jfalse5) { /*test failed */
                    $blk = 4;
                    continue;
                }
                $blk = 4; /* jump */
                continue;
                goog.asserts.fail('unterminated block');
            case 1:
                /* --- except --- */
                var $loadgbl6 = Sk.misceval.loadname('ValueError', $gbl);
                var $jfalse7 = ($loadgbl6 === false || !Sk.misceval.isTrue($loadgbl6));
                if ($jfalse7) { /*test failed */
                    $blk = 5;
                    continue;
                }
                //
                // line 6:
                //      return True
                //   ^
                //
                return true;
                goog.asserts.fail('unterminated block');
            case 2:
                /* --- orelse --- */
                $blk = 3; /* jump */
                continue;
                goog.asserts.fail('unterminated block');
            case 3:
                /* --- end --- */
                return null;
                goog.asserts.fail('unterminated block');
            case 4:
                /* --- done --- */
                return $compareres3;
                $exc.pop();
            } catch ($err) {
                $blk = $exc.pop();
                continue;
            }
            $blk = 2; /* jump */
            continue;
            goog.asserts.fail('unterminated block');
        case 5:
            /* --- except_0_ --- */
            goog.asserts.fail('unterminated block');
        }
        break;
    }
});
$scope0(new Sk.builtin.str('__main__'));

Original issue reported on code.google.com by theaj...@gmail.com on 23 Aug 2012 at 11:28

GoogleCodeExporter commented 8 years ago
I believe I have fixed this issue with

http://code.google.com/r/drchuck-skulpt-mods/source/detail?r=5729295665e16a8347a
0299a50a4e2b853e347e1

http://code.google.com/r/drchuck-skulpt-mods/source/detail?r=2f2c938e6932e6a255f
d0a13959c8956b167fb28

Original comment by drchuck on 18 Jan 2013 at 4:05