Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/rascal/src/internal/as2/hir/constant_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
expr.value = ExprKind::Constant(result);
self.anything_changed = true;
}
}

Check warning on line 30 in crates/rascal/src/internal/as2/hir/constant_folder.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/Rascal/Rascal/crates/rascal/src/internal/as2/hir/constant_folder.rs

Check warning on line 30 in crates/rascal/src/internal/as2/hir/constant_folder.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/Rascal/Rascal/crates/rascal/src/internal/as2/hir/constant_folder.rs
ExprKind::CastToInteger(value) => {
if let ExprKind::Constant(value) = &value.value
&& let Some(value) = as_int(value, i32::MIN) {
expr.value = ExprKind::Constant(ConstantKind::Integer(value));
self.anything_changed = true;
}
}
_ => {}
}
}
Expand Down Expand Up @@ -68,11 +75,11 @@
}
}

fn as_int(value: &'_ ConstantKind) -> Option<i32> {
fn as_int(value: &'_ ConstantKind, nan: i32) -> Option<i32> {
match value {
ConstantKind::String(_) => {
let value = as_float(value).unwrap_or_default();
Some(if value.is_nan() { 0 } else { value as i32 })
Some(if value.is_nan() { nan } else { value as i32 })
}
ConstantKind::Boolean(true) => Some(1),
ConstantKind::Boolean(false) => Some(0),
Expand Down Expand Up @@ -155,7 +162,7 @@
}
}
UnaryOperator::BitNot => {
if let Some(value) = as_int(value) {
if let Some(value) = as_int(value, 0) {
ConstantKind::Integer(!value)
} else {
return None;
Expand Down
Loading
Loading