Remove an unsafe access in the resolver (#5428)

This commit is contained in:
Charlie Marsh 2023-06-28 15:08:10 -04:00 committed by GitHub
parent 69c4b7fa11
commit c5e20505f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -173,8 +173,11 @@ fn resolve_module_descriptor(
resolved_paths.len() == module_descriptor.name_parts.len() resolved_paths.len() == module_descriptor.name_parts.len()
}; };
let is_partly_resolved = let is_partly_resolved = if resolved_paths.is_empty() {
!resolved_paths.is_empty() && resolved_paths.len() < module_descriptor.name_parts.len(); false
} else {
resolved_paths.len() < module_descriptor.name_parts.len()
};
ImportResult { ImportResult {
is_relative: false, is_relative: false,
@ -286,9 +289,10 @@ fn resolve_best_absolute_import<Host: host::Host>(
// If we resolved to a namespace package, ensure that all imported symbols are // If we resolved to a namespace package, ensure that all imported symbols are
// present in the namespace package's "implicit" imports. // present in the namespace package's "implicit" imports.
if typings_import.is_namespace_package if typings_import.is_namespace_package
&& typings_import.resolved_paths[typings_import.resolved_paths.len() - 1] && typings_import
.as_os_str() .resolved_paths
.is_empty() .last()
.map_or(false, |path| path.as_os_str().is_empty())
{ {
if typings_import if typings_import
.implicit_imports .implicit_imports