fix: exotic types return float on division, self on modulo
This commit is contained in:
parent
8707d14f95
commit
6db8145c00
|
@ -278,8 +278,7 @@ pub fn math_result_type(
|
|||
)
|
||||
}
|
||||
},
|
||||
Operator::Math(Math::Divide) | Operator::Math(Math::Modulo) => match (&lhs.ty, &rhs.ty)
|
||||
{
|
||||
Operator::Math(Math::Divide) => match (&lhs.ty, &rhs.ty) {
|
||||
(Type::Int, Type::Int) => (Type::Int, None),
|
||||
(Type::Float, Type::Int) => (Type::Float, None),
|
||||
(Type::Int, Type::Float) => (Type::Float, None),
|
||||
|
@ -292,6 +291,55 @@ pub fn math_result_type(
|
|||
(Type::Filesize, Type::Filesize) => (Type::Float, None),
|
||||
(Type::Filesize, Type::Int) => (Type::Filesize, None),
|
||||
(Type::Filesize, Type::Float) => (Type::Filesize, None),
|
||||
(Type::Duration, Type::Duration) => (Type::Float, None),
|
||||
(Type::Duration, Type::Int) => (Type::Duration, None),
|
||||
(Type::Duration, Type::Float) => (Type::Duration, None),
|
||||
|
||||
(Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None),
|
||||
(Type::Custom(a), _) => (Type::Custom(a.clone()), None),
|
||||
|
||||
(Type::Any, _) => (Type::Any, None),
|
||||
(_, Type::Any) => (Type::Any, None),
|
||||
(Type::Int | Type::Float | Type::Filesize | Type::Duration, _) => {
|
||||
*op = Expression::garbage(working_set, op.span);
|
||||
(
|
||||
Type::Any,
|
||||
Some(ParseError::UnsupportedOperationRHS(
|
||||
"division".into(),
|
||||
op.span,
|
||||
lhs.span,
|
||||
lhs.ty.clone(),
|
||||
rhs.span,
|
||||
rhs.ty.clone(),
|
||||
)),
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
*op = Expression::garbage(working_set, op.span);
|
||||
(
|
||||
Type::Any,
|
||||
Some(ParseError::UnsupportedOperationLHS(
|
||||
"division".into(),
|
||||
op.span,
|
||||
lhs.span,
|
||||
lhs.ty.clone(),
|
||||
)),
|
||||
)
|
||||
}
|
||||
},
|
||||
Operator::Math(Math::Modulo) => match (&lhs.ty, &rhs.ty) {
|
||||
(Type::Int, Type::Int) => (Type::Int, None),
|
||||
(Type::Float, Type::Int) => (Type::Float, None),
|
||||
(Type::Int, Type::Float) => (Type::Float, None),
|
||||
(Type::Float, Type::Float) => (Type::Float, None),
|
||||
(Type::Number, Type::Number) => (Type::Number, None),
|
||||
(Type::Number, Type::Int) => (Type::Number, None),
|
||||
(Type::Int, Type::Number) => (Type::Number, None),
|
||||
(Type::Number, Type::Float) => (Type::Number, None),
|
||||
(Type::Float, Type::Number) => (Type::Number, None),
|
||||
(Type::Filesize, Type::Filesize) => (Type::Filesize, None),
|
||||
(Type::Filesize, Type::Int) => (Type::Filesize, None),
|
||||
(Type::Filesize, Type::Float) => (Type::Filesize, None),
|
||||
(Type::Duration, Type::Duration) => (Type::Duration, None),
|
||||
(Type::Duration, Type::Int) => (Type::Duration, None),
|
||||
(Type::Duration, Type::Float) => (Type::Duration, None),
|
||||
|
|
Loading…
Reference in New Issue
Block a user