Skip to content

Commit 0e38846

Browse files
author
Alex Snaps
committed
Moar unsignedness love
1 parent 87e7137 commit 0e38846

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/common.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,17 @@ named!(pub integer_literal<CompleteByteSlice, Literal>,
880880
sign: opt!(tag!("-")) >>
881881
val: digit >>
882882
({
883-
let mut intval = i64::from_str(str::from_utf8(*val).unwrap()).unwrap();
883+
let mut intval = i128::from_str(str::from_utf8(*val).unwrap()).unwrap();
884884
if sign.is_some() {
885885
intval *= -1;
886886
}
887-
Literal::Integer(intval)
887+
if intval > std::i64::MAX as i128 {
888+
Literal::UnsignedInteger(intval as u64)
889+
} else if intval < std::i64::MIN as i128 {
890+
panic!("{:?} can't fit in a Literal::Integer", intval)
891+
} else {
892+
Literal::Integer(intval as i64)
893+
}
888894
})
889895
)
890896
);

0 commit comments

Comments
 (0)