Skip to content

Commit 3b459bf

Browse files
CopilotPh0enixKM
andcommitted
Fix trust context regression and type consistency: use Type::Int for __status, return __status in empty blocks
Co-authored-by: Ph0enixKM <29208124+Ph0enixKM@users.noreply.github.com>
1 parent a1f3ec0 commit 3b459bf

File tree

4 files changed

+9
-24
lines changed

4 files changed

+9
-24
lines changed

src/modules/condition/failed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl TranslateModule for Failed {
8787
if self.is_parsed {
8888
let block = self.block.translate(meta);
8989
// the condition of '$?' clears the status code thus we need to store it in a variable
90-
let status_variable_stmt = VarStmtFragment::new("__status", Type::Num, fragments!("$?"));
90+
let status_variable_stmt = VarStmtFragment::new("__status", Type::Int, fragments!("$?"));
9191
let status_variable_expr = VarExprFragment::from_stmt(&status_variable_stmt);
9292
if self.is_question_mark {
9393
// Set default return value if failure happened in a function

src/modules/condition/succeeded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl TranslateModule for Succeeded {
6565
if self.is_parsed {
6666
let block = self.block.translate(meta);
6767
// the condition of '$?' clears the status code thus we need to store it in a variable
68-
let status_variable_stmt = VarStmtFragment::new("__status", Type::Num, fragments!("$?"));
68+
let status_variable_stmt = VarStmtFragment::new("__status", Type::Int, fragments!("$?"));
6969
let status_variable_expr = VarExprFragment::from_stmt(&status_variable_stmt);
7070

7171
match &block {

src/modules/condition/then.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,23 @@ impl TranslateModule for Then {
7777
fn translate(&self, meta: &mut TranslateMetadata) -> FragmentKind {
7878
if self.is_parsed {
7979
let block = self.block.translate(meta);
80+
// the condition of '$?' clears the status code thus we need to store it in a variable
81+
let status_variable_stmt = VarStmtFragment::new("__status", Type::Int, fragments!("$?"));
82+
let status_variable_expr = VarExprFragment::from_stmt(&status_variable_stmt);
8083

8184
match &block {
8285
FragmentKind::Empty => {
83-
FragmentKind::Empty
86+
status_variable_stmt.to_frag()
8487
},
8588
FragmentKind::Block(block) if block.statements.is_empty() => {
86-
FragmentKind::Empty
89+
status_variable_stmt.to_frag()
8790
},
8891
_ => {
89-
let param_assignment = VarStmtFragment::new(&self.param_name, Type::Int, fragments!("$?"))
92+
let param_assignment = VarStmtFragment::new(&self.param_name, Type::Int, status_variable_expr.to_frag())
9093
.with_global_id(self.param_global_id);
9194

9295
BlockFragment::new(vec![
96+
status_variable_stmt.to_frag(),
9397
param_assignment.to_frag(),
9498
block,
9599
], false).to_frag()

src/tests/validity/unsafe_function_call.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)