Skip to content

Commit

Permalink
Add type guard to prevent crash
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Nov 13, 2024
1 parent 0edc8bd commit 16275ce
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/analyzer/expr/fetch/array_fetch_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,31 +434,33 @@ pub(crate) fn get_array_access_type_given_offset(
} => match *name {
StrId::KEYED_CONTAINER | StrId::ANY_ARRAY => {
if let Some(type_params) = type_params {
if let Some(existing_type) = stmt_type {
stmt_type = Some(add_union_type(
existing_type,
type_params.get(1).unwrap(),
codebase,
false,
));
} else {
stmt_type = Some(type_params.get(1).unwrap().clone());
if type_params.len() > 1 {
if let Some(existing_type) = stmt_type {
stmt_type = Some(add_union_type(
existing_type,
&type_params[1],
codebase,
false,
));
} else {
stmt_type = Some(type_params[1].clone());
}

has_valid_expected_offset = true;
}

has_valid_expected_offset = true;
}
}
StrId::CONTAINER => {
if let Some(type_params) = type_params {
if let Some(existing_type) = stmt_type {
stmt_type = Some(add_union_type(
existing_type,
type_params.first().unwrap(),
&type_params[0],
codebase,
false,
));
} else {
stmt_type = Some(type_params.first().unwrap().clone());
stmt_type = Some(type_params[0].clone());
}

has_valid_expected_offset = true;
Expand Down

0 comments on commit 16275ce

Please sign in to comment.