Skip to content

Commit

Permalink
Safer IntEnum and EnumInt
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed Apr 16, 2021
1 parent ae3d3d1 commit efb106b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/src/typechecker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,17 @@ impl<'a> TypeChecker<'a> {
checked_args.push(first_arg);
scope.resolve_type(&TypeName::STRING, self.pool, pos)?
}
(IntrinsicOp::EnumInt, _) => {
(IntrinsicOp::EnumInt, TypeId::Enum(_)) => {
checked_args.push(first_arg);
scope.resolve_type(&TypeName::INT32, self.pool, pos)?
}
(IntrinsicOp::IntEnum, _) if expected.is_some() => {
checked_args.push(first_arg);
expected.unwrap().clone()
if let Some(TypeId::Enum(idx)) = expected {
TypeId::Enum(*idx)
} else {
return Err(Error::type_error("Enum", expected.unwrap().pretty(self.pool)?, pos));
}
}
(IntrinsicOp::ToVariant, _) => {
checked_args.push(first_arg);
Expand Down

0 comments on commit efb106b

Please sign in to comment.