forked from M-Labs/nac3
core/magic_methods: Fix type of unary ops with primitive types
This commit is contained in:
parent
876ad6c59c
commit
937a8b9698
|
@ -476,10 +476,24 @@ pub fn typeof_unaryop(
|
||||||
return Err("The truth value of an array with more than one element is ambiguous".to_string())
|
return Err("The truth value of an array with more than one element is ambiguous".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(if operand.obj_id(unifier).is_some_and(|id| PRIMITIVE_DEF_IDS.iter().any(|prim_id| id == prim_id)) {
|
Ok(match *op {
|
||||||
Some(operand)
|
Unaryop::Not => {
|
||||||
} else {
|
match operand.obj_id(unifier) {
|
||||||
None
|
Some(v) if v == PRIMITIVE_DEF_IDS.ndarray => Some(operand),
|
||||||
|
Some(_) => Some(primitives.bool),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Unaryop::Invert
|
||||||
|
| Unaryop::UAdd
|
||||||
|
| Unaryop::USub => {
|
||||||
|
if operand.obj_id(unifier).is_some_and(|id| PRIMITIVE_DEF_IDS.iter().any(|prim_id| id == prim_id)) {
|
||||||
|
Some(operand)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue