Skip to content

Commit 570ebc0

Browse files
committed
Merge branch 'master' of github.com:FuelLabs/sway into vaivaswatha/arg_mut_analysis
2 parents 44abfd4 + 4f1af43 commit 570ebc0

File tree

26 files changed

+183
-94
lines changed

26 files changed

+183
-94
lines changed

forc-plugins/forc-client/src/cmd/call.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ pub struct Command {
419419
#[clap(long, short = 'o', default_value = "default", help_heading = "OUTPUT")]
420420
pub output: OutputFormat,
421421

422+
/// Contract call variable output count
423+
#[clap(long, alias = "variable-output", help_heading = "VARIABLE OUTPUT")]
424+
pub variable_output: Option<usize>,
425+
422426
/// Set verbosity levels; currently only supports max 2 levels
423427
/// - `-v=1`: Print decoded logs
424428
/// - `-v=2`: Additionally print receipts and script json

forc-plugins/forc-client/src/op/call/call_function.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub async fn call_function(
5050
mut output,
5151
external_contracts,
5252
contract_abis,
53+
variable_output,
5354
..
5455
} = cmd;
5556

@@ -88,7 +89,9 @@ pub async fn call_function(
8889
};
8990

9091
// Setup variable output policy and log decoder
91-
let variable_output_policy = VariableOutputPolicy::Exactly(call_parameters.amount as usize);
92+
let variable_output_policy = variable_output
93+
.map(VariableOutputPolicy::Exactly)
94+
.unwrap_or(VariableOutputPolicy::EstimateMinimum);
9295
let error_codes = abi
9396
.unified
9497
.error_codes
@@ -275,8 +278,6 @@ pub async fn call_function(
275278
let fuel_tx::Transaction::Script(script) = &tx else {
276279
bail!("Transaction is not a script");
277280
};
278-
let script_json = serde_json::to_value(script)
279-
.map_err(|e| anyhow!("Failed to convert script to JSON: {e}"))?;
280281

281282
// Parse the result based on output format
282283
let mut receipt_parser =
@@ -330,7 +331,7 @@ pub async fn call_function(
330331

331332
super::display_detailed_call_info(
332333
&tx_execution,
333-
&script_json,
334+
script,
334335
&abi_map,
335336
cmd.verbosity,
336337
&mut output,
@@ -357,7 +358,7 @@ pub async fn call_function(
357358
result: Some(result),
358359
total_gas: *tx_execution.result.total_gas(),
359360
receipts: tx_execution.result.receipts().to_vec(),
360-
script_json: Some(script_json),
361+
script: Some(script.to_owned()),
361362
trace_events,
362363
})
363364
}
@@ -466,6 +467,7 @@ pub mod tests {
466467
cmd,
467468
op::call::{call, get_wallet, PrivateKeySigner},
468469
};
470+
use fuel_tx::field::Outputs;
469471
use fuels::{crypto::SecretKey, prelude::*};
470472
use std::path::PathBuf;
471473

@@ -493,6 +495,7 @@ pub mod tests {
493495
label: None,
494496
output: cmd::call::OutputFormat::Raw,
495497
list_functions: false,
498+
variable_output: None,
496499
verbosity: 0,
497500
debug: false,
498501
}
@@ -948,15 +951,9 @@ pub mod tests {
948951
gas_forwarded: None,
949952
};
950953
// validate balance is unchanged (dry-run)
951-
assert_eq!(
952-
call(operation.clone(), cmd.clone())
953-
.await
954-
.unwrap()
955-
.result
956-
.unwrap(),
957-
"()"
958-
);
959-
assert_eq!(get_contract_balance(id_2, provider.clone()).await, 0);
954+
let call_response = call(operation.clone(), cmd.clone()).await.unwrap();
955+
assert_eq!(call_response.result.unwrap(), "()");
956+
assert_eq!(call_response.script.unwrap().outputs().len(), 2);
960957
cmd.mode = cmd::call::ExecutionMode::Live;
961958
assert_eq!(call(operation, cmd).await.unwrap().result.unwrap(), "()");
962959
assert_eq!(get_contract_balance(id_2, provider.clone()).await, 1);
@@ -983,7 +980,9 @@ pub mod tests {
983980
};
984981
cmd.mode = cmd::call::ExecutionMode::Live;
985982
let operation = cmd.validate_and_get_operation().unwrap();
986-
assert_eq!(call(operation, cmd).await.unwrap().result.unwrap(), "()");
983+
let call_response = call(operation, cmd).await.unwrap();
984+
assert_eq!(call_response.result.unwrap(), "()");
985+
assert_eq!(call_response.script.unwrap().outputs().len(), 3);
987986
assert_eq!(
988987
get_recipient_balance(random_wallet.address(), provider.clone()).await,
989988
2
@@ -1041,7 +1040,9 @@ pub mod tests {
10411040
};
10421041
cmd.mode = cmd::call::ExecutionMode::Live;
10431042
let operation = cmd.validate_and_get_operation().unwrap();
1044-
assert_eq!(call(operation, cmd).await.unwrap().result.unwrap(), "()");
1043+
let call_response = call(operation, cmd).await.unwrap();
1044+
assert_eq!(call_response.result.unwrap(), "()");
1045+
assert_eq!(call_response.script.unwrap().outputs().len(), 3);
10451046
assert_eq!(
10461047
get_recipient_balance(random_wallet.address(), provider.clone()).await,
10471048
3

forc-plugins/forc-client/src/op/call/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct CallResponse {
4545
#[serde(skip_serializing_if = "Vec::is_empty")]
4646
pub trace_events: Vec<trace::TraceEvent>,
4747
#[serde(rename = "Script", skip_serializing_if = "Option::is_none")]
48-
pub script_json: Option<serde_json::Value>,
48+
pub script: Option<fuel_tx::Script>,
4949
}
5050

5151
/// A command for calling a contract function.
@@ -266,7 +266,7 @@ pub(crate) fn display_tx_info(
266266
/// Prints receipts and trace to the writer based on verbosity level
267267
pub(crate) fn display_detailed_call_info(
268268
tx: &TransactionExecutionStatus,
269-
script_json: &serde_json::Value,
269+
script: &fuel_tx::Script,
270270
abis: &HashMap<ContractId, Abi>,
271271
verbosity: u8,
272272
writer: &mut impl std::io::Write,
@@ -276,7 +276,7 @@ pub(crate) fn display_detailed_call_info(
276276
if verbosity >= 4 {
277277
forc_tracing::println_label_green(
278278
"transaction script:\n",
279-
&serde_json::to_string_pretty(script_json).unwrap(),
279+
&serde_json::to_string_pretty(script).unwrap(),
280280
);
281281
}
282282
if verbosity >= 3 {

forc-plugins/forc-client/src/op/call/transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub async fn transfer(
4848
total_gas: tx_response.tx_status.total_gas,
4949
result: None,
5050
receipts: tx_response.tx_status.receipts,
51-
script_json: None,
51+
script: None,
5252
trace_events: vec![],
5353
})
5454
}

forc-plugins/forc-mcp/src/forc_call/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ fn build_call_command(
540540
gas,
541541
external_contracts: None,
542542
output: OutputFormat::Json,
543+
variable_output: None,
543544
verbosity,
544545
debug: false,
545546
})
@@ -582,6 +583,7 @@ fn build_list_command(contract_id: &str, abi: &str) -> anyhow::Result<forc_clien
582583
gas: None,
583584
external_contracts: None,
584585
output: OutputFormat::Default,
586+
variable_output: None,
585587
verbosity: 0,
586588
debug: false,
587589
})
@@ -641,6 +643,7 @@ fn build_transfer_command(
641643
gas: None,
642644
external_contracts: None,
643645
output: OutputFormat::Json,
646+
variable_output: None,
644647
verbosity,
645648
debug: false,
646649
})

forc-plugins/forc-node/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ mod tests {
257257
fn test_human_readable_config() {
258258
let config = Config::local_node();
259259
let human_readable = HumanReadableConfig(&config);
260-
let formatted = format!("{}", human_readable);
260+
let formatted = format!("{human_readable}");
261261
let expected = format!(
262262
r#"Fuel Core Configuration:
263263
GraphQL Address: {}

sway-core/src/language/ty/declaration/const_generic.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ impl MaterializeConstGenerics for TyConstGenericDecl {
5454
.unwrap()
5555
.cast_value_to_u64()
5656
.unwrap(),
57-
"{:?} {:?}",
58-
v,
59-
value
57+
"{v:?} {value:?}",
6058
);
6159
}
6260
None => {

sway-core/src/semantic_analysis/namespace/trait_map.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,24 @@ impl DebugWithEngines for TypeRootFilter {
236236
U64 => write!(f, "u64"),
237237
U256 => write!(f, "u256"),
238238
Bool => write!(f, "bool"),
239-
Custom(name) => write!(f, "Custom({})", name),
239+
Custom(name) => write!(f, "Custom({name})"),
240240
B256 => write!(f, "b256"),
241241
Contract => write!(f, "Contract"),
242242
ErrorRecovery => write!(f, "ErrorRecovery"),
243-
Tuple(n) => write!(f, "Tuple(len={})", n),
243+
Tuple(n) => write!(f, "Tuple(len={n})"),
244244
Enum(parsed_id) => {
245-
write!(f, "Enum({:?})", parsed_id)
245+
write!(f, "Enum({parsed_id:?})")
246246
}
247247
Struct(parsed_id) => {
248-
write!(f, "Struct({:?})", parsed_id)
248+
write!(f, "Struct({parsed_id:?})")
249249
}
250-
ContractCaller(abi_name) => write!(f, "ContractCaller({})", abi_name),
250+
ContractCaller(abi_name) => write!(f, "ContractCaller({abi_name})"),
251251
Array => write!(f, "Array"),
252252
RawUntypedPtr => write!(f, "RawUntypedPtr"),
253253
RawUntypedSlice => write!(f, "RawUntypedSlice"),
254254
Ptr => write!(f, "Ptr"),
255255
Slice => write!(f, "Slice"),
256-
TraitType(name) => write!(f, "TraitType({})", name),
256+
TraitType(name) => write!(f, "TraitType({name})"),
257257
}
258258
}
259259
}
@@ -324,14 +324,13 @@ impl DebugWithEngines for TraitMap {
324324

325325
writeln!(
326326
f,
327-
" impl {} for {} [{}]{} {{",
328-
trait_name_str, ty_str, iface_flag, impl_tparams
327+
" impl {trait_name_str} for {ty_str} [{iface_flag}]{impl_tparams} {{"
329328
)?;
330329

331330
for (name, item) in &value.trait_items {
332331
match item {
333332
ResolvedTraitImplItem::Parsed(_p) => {
334-
writeln!(f, " - {}: <parsed>", name)?;
333+
writeln!(f, " - {name}: <parsed>")?;
335334
}
336335
ResolvedTraitImplItem::Typed(ty_item) => {
337336
writeln!(f, " - {}: {:?}", name, engines.help_out(ty_item))?;

sway-error/src/warning.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::{
22
diagnostic::{Code, Diagnostic, Hint, Issue, Reason, ToDiagnostic},
33
formatting::{
4-
did_you_mean_help, num_to_str, sequence_to_list, sequence_to_str, Enclosing, Indent,
4+
did_you_mean_help, first_line, num_to_str, sequence_to_list, sequence_to_str, Enclosing,
5+
Indent,
56
},
67
};
78

@@ -245,7 +246,7 @@ impl fmt::Display for Warning {
245246
},
246247
UnusedReturnValue { r#type } => write!(
247248
f,
248-
"This returns a value of type {type}, which is not assigned to anything and is \
249+
"This returns a value of type \"{type}\", which is not assigned to anything and is \
249250
ignored."
250251
),
251252
SimilarMethodFound { lib, module, name } => write!(
@@ -593,6 +594,25 @@ impl ToDiagnostic for CompileWarning {
593594
},
594595
help: vec![],
595596
},
597+
UnusedReturnValue { r#type } => Diagnostic {
598+
reason: Some(Reason::new(code(1), "Returned value is ignored".to_string())),
599+
issue: Issue::warning(
600+
source_engine,
601+
self.span(),
602+
"This returns a value which is not assigned to anything and is ignored.".to_string(),
603+
),
604+
hints: vec![
605+
Hint::help(
606+
source_engine,
607+
self.span(),
608+
format!("The returned value has type \"{type}\"."),
609+
)
610+
],
611+
help: vec![
612+
"If you want to intentionally ignore the returned value, use `let _ = ...`:".to_string(),
613+
format!("{}let _ = {};", Indent::Single, first_line(self.span.as_str(), true)),
614+
],
615+
},
596616
_ => Diagnostic {
597617
// TODO: Temporarily we use self here to achieve backward compatibility.
598618
// In general, self must not be used and will not be used once we

sway-lib-std/src/clone.sw

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ fn ok_string_array_clone() {
7878
let a = __to_str_array("abc");
7979
let b = a.clone();
8080

81-
let _ = __dbg(a); // TODO __dbg((a, b)) is not working
82-
let _ = __dbg(b);
81+
let _ = __dbg((a, b));
8382

8483
assert(a == __to_str_array("abc"));
8584
assert(b == __to_str_array("abc"));

0 commit comments

Comments
 (0)