Add basic in operator support

This commit is contained in:
Arthur Targaryen
2021-10-09 00:53:28 +02:00
parent 563a0b92b5
commit 8783cf0138
4 changed files with 95 additions and 1 deletions

View File

@ -273,6 +273,27 @@ pub fn math_result_type(
)
}
},
Operator::In => match (&lhs.ty, &rhs.ty) {
(t, Type::List(u)) if type_compatible(t, u) => (Type::Bool, None),
(Type::Int | Type::Float, Type::Range) => (Type::Bool, None),
(Type::String, Type::String) => (Type::Bool, None),
(Type::Unknown, _) => (Type::Bool, None),
(_, Type::Unknown) => (Type::Bool, None),
_ => {
*op = Expression::garbage(op.span);
(
Type::Unknown,
Some(ParseError::UnsupportedOperation(
op.span,
lhs.span,
lhs.ty.clone(),
rhs.span,
rhs.ty.clone(),
)),
)
}
},
_ => {
*op = Expression::garbage(op.span);