File tree Expand file tree Collapse file tree 3 files changed +20
-9
lines changed
crates/static-analysis-kernel/src/analysis/languages Expand file tree Collapse file tree 3 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -113,15 +113,23 @@ pub fn parse_imports_with_tree<'text>(
113113 }
114114 }
115115
116- let package_node = package_node. expect ( "query invariant: value should be Some" ) ;
117- let target = target. expect ( "query invariant: value should be Some" ) ;
116+ let Some ( package_node) = package_node else {
117+ debug_assert ! ( false , "query invariant: value should be Some" ) ;
118+ continue ;
119+ } ;
120+ let Some ( target) = target else {
121+ debug_assert ! ( false , "query invariant: value should be Some" ) ;
122+ continue ;
123+ } ;
118124 // Due to the way the tree-sitter-java grammar is defined, when there is an asterisk, what
119125 // we've captured as the `import_child` will represent the full text of the package.
120126 // Otherwise, what we've captured as `package` will.
127+ let Some ( import_child_node) = import_child_node else {
128+ debug_assert ! ( false , "query invariant: value should be Some" ) ;
129+ continue ;
130+ } ;
121131 let package = match target {
122- ImportTarget :: Wildcard => {
123- import_child_node. expect ( "query invariant: value should be Some" )
124- }
132+ ImportTarget :: Wildcard => import_child_node,
125133 ImportTarget :: Class ( _) => package_node,
126134 } ;
127135 imports. push ( Import { package, target } ) ;
Original file line number Diff line number Diff line change @@ -216,8 +216,10 @@ pub(crate) fn parse_imports_with_tree_inner<'text>(
216216 name = imported_from. take ( ) ;
217217 }
218218
219+ debug_assert ! ( name. is_some( ) , "name should always be set" ) ;
220+ let name = name?;
219221 Some ( PackageImport {
220- name : name . expect ( "name should always be set" ) ,
222+ name,
221223 imported_from,
222224 } )
223225 } )
Original file line number Diff line number Diff line change @@ -104,9 +104,10 @@ impl<'a> Import<'a> {
104104 /// from ..common_utils.local_utils import print_array # Some(Import("common_utils"))
105105 /// ```
106106 pub fn parent_import ( & self ) -> Option < Import < ' a > > {
107- self . full_text . rsplit_once ( '.' ) . map ( |( parent, _) | {
108- Import :: try_new ( parent, None , None , self . is_relative )
109- . expect ( "full_text should not have whitespace" )
107+ self . full_text . rsplit_once ( '.' ) . and_then ( |( parent, _) | {
108+ let import = Import :: try_new ( parent, None , None , self . is_relative ) ;
109+ debug_assert ! ( import. is_ok( ) ) ;
110+ import. ok ( )
110111 } )
111112 }
112113}
You can’t perform that action at this time.
0 commit comments