near / near-sdk-contract-tools

Helpful functions and macros for developing smart contracts on NEAR Protocol.
https://crates.io/crates/near-sdk-contract-tools
Apache License 2.0
41 stars 10 forks source link

Disallow event name collisions within single macro invocation #107

Closed encody closed 1 year ago

encody commented 1 year ago
#[event(standard = "x-name-collision", version = "1.0.0")]
enum NameCollision {
    First,
    #[nep297(name = "first")]
    Second,
}

println!("{}", NameCollision::First.to_event_string());
println!("{}", NameCollision::Second.to_event_string());

Output:

EVENT_JSON:{"standard":"x-name-collision","version":"1.0.0","event":"first","data":null}
EVENT_JSON:{"standard":"x-name-collision","version":"1.0.0","event":"first","data":null}

Though this technically has a "valid" use-case (wherein a single event's data can take multiple forms), it is almost always better to use another enum for the metadata type instead of having two events using the same name.

This issue is resolved when the above code produces a compiler error. Obviously it is much more difficult to make separate macro invocations produce a compiler error together, even if they are using the same standard field value.