def f(t: Type): return match(t)(lambda T: { Type.array(T): T, T: Type('double'), })
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), })
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')
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'))
def test_type_array_literal_success(): from tmppy import Type assert Type.array(Type('int')) == Type.array(Type('int'))
def f(x: bool): return Type.array( 5 ) # error: The argument passed to Type.array\(\) should have type Type, but was: int
def f(x: bool): return Type.array( 'x', 'y') # error: Type.array\(\) takes 1 argument. Got: 2
def f(x: bool): return Type.array( x=1 ) # error: Keyword arguments are not supported in Type.array\(\)