JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
88 stars 4 forks source link

Match in Python trips up Python parser in tests #386

Open JSAbrahams opened 1 year ago

JSAbrahams commented 1 year ago

Description of Bug

It appears that the python parser trips up as soon as it encounters a match in Python. When testing, everything before that is parsed. We can test this by modifying this in one of the test resources and verify that the associate test fails (assuming we don't modify the associate check resource). However, if we perform modifications after the match, it fails.

How to Reproduce

Take Mamba file resource/valid/error/nested_exception.mamba:

class MyException1(msg: String): Exception(msg)
class MyException2(msg: String): Exception(msg)

def f(x: Int) -> Int raise [MyException1, MyException2] =>
    match x
        0 => 20
        1 => raise MyException1()
        2 => raise MyException2()

def g() -> Int raise [MyException2] =>
    f(2) handle
        err: MyException1 => print("a")

g()

For reference, this is the associate nested_exception_check,py resource:

class MyException1(Exception):
    def __init__(self, msg: str):
        Exception.__init__(self, msg)

class MyException2(Exception):
    def __init__(self, msg: str):
        Exception.__init__(self, msg)

def f(x: int) -> int:
    match x:
        case 0:
            return 20
        case 1:
            raise MyException1()
        case 2:
            raise MyException2()

def g() -> int:
    try:
        f(2)
    except Exception as err:
        print("a")

g()

Expected behavior

The test should fail as soon as the output deviates from the resource.

Additional context

This is a bug in python parser v 0.1.0. We could update to version 0.2.0, but this only goes up to Python 3.7 it appears. Therefore, we may need to search for another crate which parses Python files for us. Furthermore, there appear breaking changes when going from 0.1.0 to 0.2.0, so even if 0.2.0 does in fact resolve the issue, we do need to perform non-trivial changes.

JSAbrahams commented 1 year ago

Perhaps we should fork that crate and see if we can't implement this ourselves