def unpack_tuple(t: Type): return match(t)(lambda Ts: { Type.template_instantiation('std::tuple', [*Ts]): match(Type('int'))(lambda T: { T: Ts }) })
def f(x: Type, y: Type): return match(x)(lambda T, U: { T: y, Type.pointer(Type.function(T, [U])): match(T, U)(lambda V: { (Type('int'), V): y, (Type('float'), V): Type('bool'), }), })
def f(t: Type): return match(t)(lambda T: { Type.array(T): T, T: Type('double'), })
def f(x: Type): return match(x)(lambda T: { T: T, Type.pointer(Type.function(Type('int'), empty_list(Type))): Type('bool'), })
def f(x: Type): return match(x)( lambda T, U: { Type.pointer(Type.function(T, [U])): h(T)(Type('double')), Type.pointer(Type.function(Type('int'), [T])): T, Type.pointer(Type.function(Type('float'), [T])): T, })
def _f(t: Type): return match(t)(lambda T: { T: Type.reference(T), Type.pointer(T): Type.rvalue_reference(T), })
def unpack_tuple_of_tuples(t: Type): return match(t)(lambda Ts, Us: { Type.template_instantiation('std::tuple', [ Type.template_instantiation('std::tuple', [*Ts]), Type.template_instantiation('std::tuple', [*Us]) ]): [Ts, Us] })
def f(t: Type): return match(t)(lambda X: { Type.template_instantiation('std::tuple', [*X]): X, Type.template_instantiation('std::tuple', [Type('int'), X]): [X], })
def f(b: bool): return match( X(True) )( # error: All arguments passed to match must have type Type, but an argument with type X was specified. lambda x: { x: x, })
def f(y: Type): return match(Type.pointer(Type('int')), y)(lambda T, U: { (T, U): False, (Type.pointer(T), Type.pointer(U)): True, })
def unpack_tuple_of_tuples(t: Type): return match(t)(lambda Ts: { Type.template_instantiation('std::tuple', [Type.template_instantiation('std::tuple', [*Ts]), Type.template_instantiation('std::tuple', [Type('int'), *Ts])]): Ts, })
def f(x: Type): return match(x)(lambda T, U: { T: # note: A previous specialization that specializes nothing was here Type('double'), U: # error: Found multiple specializations that specialize nothing Type('int'), })
def f(x: Type): return match(x)(lambda T, U: { Type.pointer(Type.function(T, [U])): Type('double'), # note: A previous branch returning a Type was here. Type.pointer(Type.function(Type('int'), [T])): True, # error: All branches in a match\(\) must return the same type, but this branch returns a bool while a previous branch in this match expression returns a Type })
def f(t: Type): return match(t)(lambda T: { Type('int'): Type('int'), T: Type('double'), })
def f(x: Type): return match(x)(lambda T, U: { Type.pointer(Type.function(T, [U])): Type('double'), Type.pointer(Type.function(Type('int'), [T])): T, }, wrong_arg=True ) # error: Keyword arguments are not allowed in match
def f(t: Type): return match(t)( lambda T: { Type.template_instantiation('std::tuple', [T, Type('float')]): T, T: Type('double'), })
def f(t: Type): return match(t)(lambda T: { Type.rvalue_reference(T): T, T: Type('double'), })
def f(x: Type): return match(x, x)({ TypePattern('T', wrong_arg=x): # error: Keyword arguments in TypePattern are not supported yet. lambda T: T, })
def f(x: Type, y: Type): return match(x)({ TypePattern('T'): lambda T: y, TypePattern('T(*)(U)'): lambda T, U: match(T, U)({ TypePattern('int', 'V'): lambda V: y, TypePattern('float', 'V'): lambda V: Type('bool'), }), })
def f(x: Type): return match(x)( lambda: { {n for n in {1, 2}}: # error: Set comprehensions are not allowed in match patterns x, })
def f(x: Type): n = 5 return match(x)( lambda: { -n: # error: The "-" operator is not allowed in match patterns x, })
def f(x: Type): return match(x)( lambda Baz: # error: The lambda argument Baz was not used in any pattern, it should be removed. { Type('Bar'): Type('double'), })
def f(x: Type): return match( True )( # error: All arguments passed to match must have type Type, but an argument with type bool was specified. lambda T: { T: T, })
def f(x: Type): result = match(x)(lambda T, U: { Type.pointer(Type.function(T, [U])): Type('double'), Type.pointer(Type.function(Type('int'), [T])): id(T), Type.pointer(Type.function(Type('float'), [T])): T, }) return result
def f(x: Type): return match(x)(lambda T, U: { # error: Malformed match\(\) Type.pointer(Type.function(T, [U])): Type('double'), Type.pointer(Type.function(Type('int'), [T])): T, }, {})
def f(y: Type): return match(Type('int*'), y)({ TypePattern('T', 'U'): lambda T, U: False, TypePattern('T*', 'U*'): lambda T, U: True, })
def f(x: Type): return match(x)({ TypePattern('T'): # note: A previous specialization that specializes nothing was here lambda T: Type('double'), TypePattern('U'): # error: Found multiple specializations that specialize nothing lambda U: Type('double'), })
def f(x: Type): return match(x)({ TypePattern('T(*)(U)'): lambda T, U: Type('double'), # note: A previous lambda returning a Type was here. TypePattern('int(*)(T)'): lambda T: True, # error: All lambdas in a match\(...\)\({...}\) expression should return the same type, but this lambda returns a bool while a previous lambda in this match expression returns a Type })
def f(x: Type): return match(x)({ TypePattern('T'): lambda T: T, TypePattern('int(*)()'): lambda: Type('bool'), })
def f(t: Type): return match(t)(lambda X: { Type.template_instantiation('std::tuple', [Type.template_instantiation('std::tuple', [*X]), # note: A previous match as a List\[Type\] was here Type.template_instantiation('std::tuple', [X])]): # error: Can't match X as a Type because it was already used to match a List\[Type\] Type('int'), })