Skip to content

Commit

Permalink
fix(macros): collision when command is named cmd (#1802)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 12, 2021
1 parent 1ab8dd9 commit d36b726
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-command-named-cmd.md
@@ -0,0 +1,5 @@
---
"tauri-macros": patch
---

Fixes a name collision when the command function is named `cmd`.
6 changes: 3 additions & 3 deletions core/tauri-macros/src/command/handler.rs
Expand Up @@ -52,11 +52,11 @@ impl From<Handler> for proc_macro::TokenStream {
}: Handler,
) -> Self {
quote::quote!(move |invoke| {
let cmd = invoke.message.command();
match cmd {
let __tauri_cmd__ = invoke.message.command();
match __tauri_cmd__ {
#(stringify!(#commands) => #wrappers!(#paths, invoke),)*
_ => {
invoke.resolver.reject(format!("command {} not found", cmd))
invoke.resolver.reject(format!("command {} not found", __tauri_cmd__))
},
}
})
Expand Down
3 changes: 3 additions & 0 deletions examples/commands/src-tauri/src/commands.rs
Expand Up @@ -4,6 +4,9 @@

use tauri::{command, State};

#[command]
pub fn cmd(_argument: String) {}

#[command]
pub fn simple_command(argument: String) {
println!("{}", argument);
Expand Down
2 changes: 2 additions & 0 deletions examples/commands/src-tauri/src/main.rs
Expand Up @@ -9,6 +9,7 @@

// we move some basic commands to a separate module just to show it works
mod commands;
use commands::cmd;

use serde::Deserialize;
use tauri::{command, Params, State, Window};
Expand Down Expand Up @@ -167,6 +168,7 @@ fn main() {
force_async_with_result,
commands::simple_command,
commands::stateful_command,
cmd,
async_simple_command,
future_simple_command,
async_stateful_command,
Expand Down

0 comments on commit d36b726

Please sign in to comment.