Exemplo n.º 1
0
 def f(t: Type):
     return match(t)(lambda T: {
         Type.array(T):
             T,
         T:
             Type('double'),
     })
Exemplo n.º 2
0
 def _f(t: Type):
     return match(t)(lambda T: {
         T:
             Type.reference(T),
         Type.pointer(T):
             Type.rvalue_reference(T),
         Type.pointer(Type.pointer(T)):
             Type.array(T),
     })
Exemplo n.º 3
0
def test_array_type_expr_as_match_expr_matched_success():
    from tmppy import Type, match

    def f(t: Type):
        return match(t)(lambda T: {
            Type.array(T): T,
            T: Type('double'),
        })

    assert f(Type.array(Type('int'))) == Type('int')
Exemplo n.º 4
0
def test_match_optimization_with_multiple_specializations_chooses_more_specific_specialization():
    from tmppy import Type, match
    def _f(t: Type):
        return match(t)(lambda T: {
            T:
                Type.reference(T),
            Type.pointer(T):
                Type.rvalue_reference(T),
            Type.pointer(Type.pointer(T)):
                Type.array(T),
        })
    assert _f(Type.pointer(Type.pointer(Type('int')))) == Type.array(Type('int'))
Exemplo n.º 5
0
def test_type_array_literal_success():
    from tmppy import Type
    assert Type.array(Type('int')) == Type.array(Type('int'))
Exemplo n.º 6
0
 def f(x: bool):
     return Type.array(
         5
     )  # error: The argument passed to Type.array\(\) should have type Type, but was: int
Exemplo n.º 7
0
 def f(x: bool):
     return Type.array(
         'x', 'y')  # error: Type.array\(\) takes 1 argument. Got: 2
Exemplo n.º 8
0
 def f(x: bool):
     return Type.array(
         x=1
     )  # error: Keyword arguments are not supported in Type.array\(\)