Skip to content

Commit

Permalink
Fix 'literal too large error' for hex literals
Browse files Browse the repository at this point in the history
  • Loading branch information
g-r-a-n-t committed Feb 12, 2021
1 parent 4db24c7 commit 6a7c162
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/shorthand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::yul;
macro_rules! literal {
{[$e:expr]} => {$e};
{($e:expr)} => {yul::Literal { literal: $e.to_string(), yultype: None }};
{$l:literal} => {yul::Literal { literal: stringify!($l).to_string(), yultype: None }};
{$l:tt} => {yul::Literal { literal: stringify!($l).to_string(), yultype: None }};
}

/// Creates a Yul literal expression.
Expand Down Expand Up @@ -178,8 +178,8 @@ macro_rules! expression {
{[$e:expr]} => {$e};
{($($expression:tt)*)} => {expression! {$($expression)*}};
{$name:tt($($args:tt)*)} => {function_call_expression! {$name($($args)*)}};
{$l:literal} => {literal_expression! {$l}};
{$i:ident} => {identifier_expression! {$i}};
{$l:tt} => {literal_expression! {$l}};
}

/// Creates a vec of Yul expressions.
Expand Down Expand Up @@ -363,6 +363,15 @@ macro_rules! for_loop {
mod tests {
use crate::yul;

#[test]
fn literal_hex() {
assert_eq!(
literal! { 0x4200000000000000000000000000000000000000000000000000000000420026 }
.to_string(),
"0x4200000000000000000000000000000000000000000000000000000000420026"
)
}

#[test]
fn literal_string() {
assert_eq!(literal! {"foo"}.to_string(), r#""foo""#)
Expand Down Expand Up @@ -499,6 +508,15 @@ mod tests {
assert_eq!(assignment! {foo := 42}.to_string(), "foo := 42")
}

#[test]
fn large_assignment() {
assert_eq!(
assignment! { foo := 0x4200000000000000000000000000000000000000000000000000000000420026 }
.to_string(),
"foo := 0x4200000000000000000000000000000000000000000000000000000000420026"
)
}

#[test]
fn statement_function() {
let _42 = expression! {42};
Expand Down Expand Up @@ -554,7 +572,6 @@ mod tests {
)
}


#[test]
fn code() {
assert_eq!(
Expand Down

0 comments on commit 6a7c162

Please sign in to comment.