Beispiel #1
0
def test_if_some_arg():
    inc_type = Func[[IntType], IntType]
    foo_type1 = None  # to simulate TypeVar[None]
    foo_type2 = Record[{'bar': Option[IntType]}]
    env = {'inc': inc_type, 'foo': foo_type1}
    check_expr_type(
        """
        if-some [x #foo.bar] (inc x)
        """,
        Tuple.typed(Option[IntType], [
            Symbol.typed(IF_SOME1_TYPE, 'if-some'),
            List([
                Symbol('x'),
                Tuple.typed(Option[IntType], [
                    Symbol.typed(GET_TYPE, 'get'),
                    Placeholder.typed(foo_type2, 'foo'),
                    Symbol('bar'),
                ]),
            ]),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Symbol.typed(IntType, 'x'),
            ]),
        ]),
        env,
    )
Beispiel #2
0
def test_infer():
    inc_type = Func[[IntType], IntType]
    foo_type = Func[[NamedArg['arg', IntType]], IntType]
    check_expr_type(
        """
        def foo
          inc #arg
        """,
        Tuple.typed(foo_type, [
            Symbol.typed(DEF_TYPE, 'def'),
            Symbol('foo'),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Placeholder.typed(IntType, 'arg'),
            ])
        ]),
        {'inc': inc_type},
    )
Beispiel #3
0
def test_record_infer():
    bar_type = Record[{'baz': IntType}]
    inc_type = Func[[IntType], IntType]
    foo_type = Func[[NamedArg['bar', bar_type]], IntType]
    check_expr_type(
        """
        def foo
          inc #bar.baz
        """,
        Tuple.typed(foo_type, [
            Symbol.typed(DEF_TYPE, 'def'),
            Symbol('foo'),
            Tuple.typed(IntType, [
                Symbol.typed(inc_type, 'inc'),
                Tuple.typed(IntType, [
                    Symbol.typed(GET_TYPE, 'get'),
                    Placeholder.typed(bar_type, 'bar'),
                    Symbol('baz'),
                ]),
            ])
        ]),
        {'inc': inc_type},
    )