Skip to content

Commit

Permalink
fix(sol-macro): correct TypeArray::is_abi_dynamic (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Oct 9, 2023
1 parent 62c7d35 commit 9295e7e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
15 changes: 15 additions & 0 deletions crates/sol-types/tests/sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ fn rust_keywords() {
}

// TODO
// https://github.com/alloy-rs/core/issues/347
// https://github.com/alloy-rs/core/issues/351
#[test]
#[cfg(TODO)]
fn contract_type() {
Expand All @@ -469,6 +471,19 @@ fn contract_type() {
}
}

// https://github.com/alloy-rs/core/issues/352
#[test]
fn word_dynarray_event() {
sol! {
event Dynamic1(string[] indexed);
event Dynamic2(string[] indexed, bytes[] indexed);

event Word1(address[] indexed);
event Word2(address[] indexed, bytes32[] indexed);
event Word3(address[] indexed, bytes32[] indexed, uint256[] indexed);
}
}

// TODO: make commented out code work
#[test]
fn paths_resolution_1() {
Expand Down
15 changes: 14 additions & 1 deletion crates/syn-solidity/src/item/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
kw, utils::DebugPunctuated, ParameterList, SolIdent, Spanned, Type, VariableDeclaration,
};
use proc_macro2::Span;
use std::fmt::{self, Debug};
use std::fmt;
use syn::{
parenthesized,
parse::{Parse, ParseStream},
Expand Down Expand Up @@ -178,6 +178,19 @@ pub struct EventParameter {
pub name: Option<SolIdent>,
}

impl fmt::Display for EventParameter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.ty.fmt(f)?;
if self.indexed.is_some() {
f.write_str(" indexed")?;
}
if let Some(name) = &self.name {
write!(f, " {name}")?;
}
Ok(())
}
}

impl fmt::Debug for EventParameter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EventParameter")
Expand Down
4 changes: 2 additions & 2 deletions crates/syn-solidity/src/type/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ impl TypeArray {
/// See [`Type::is_abi_dynamic`].
pub fn is_abi_dynamic(&self) -> bool {
match self.size {
Some(_) => false,
None => self.ty.is_abi_dynamic(),
Some(_) => self.ty.is_abi_dynamic(),
None => true,
}
}

Expand Down

0 comments on commit 9295e7e

Please sign in to comment.