Skip to content

Commit

Permalink
Emit a warning when the case of the import file differ from the case …
Browse files Browse the repository at this point in the history
…of the file that was imported

Fixes #4265

Not easy to test since this is platform dependent
  • Loading branch information
ogoffart committed Oct 18, 2024
1 parent d818bf8 commit b0a1ae5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion internal/compiler/typeloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,25 @@ impl TypeLoader {
.tl
.resolve_import_path(import_token.as_ref(), file_to_import)
{
Some(x) => x,
Some(x) => {
if let Some(file_name) = x.0.file_name().and_then(|f| f.to_str()) {
let len = file_to_import.len();
if !file_to_import.ends_with(file_name)
&& len >= file_name.len()
&& file_name.eq_ignore_ascii_case(
&file_to_import.get(len - file_name.len()..).unwrap_or(""),
)
{
if import_token.as_ref().and_then(|x| x.source_file()).is_some() {
borrowed_state.diag.push_warning(
format!("Loading \"{file_to_import}\" resolved to a file named \"{file_name}\" with different casing. This behavior is not cross platform. Rename the file, or edit the import to use the same casing"),
&import_token,
);
}
}
}
x
}
None => {
let import_path = crate::pathutils::clean_path(Path::new(file_to_import));
if import_path.exists() {
Expand Down

0 comments on commit b0a1ae5

Please sign in to comment.