Skip to content

Commit

Permalink
add typecheck error for missing default export
Browse files Browse the repository at this point in the history
  • Loading branch information
NitantP committed Aug 17, 2024
1 parent d405ad5 commit 49eda2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions checker/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ pub(crate) enum TypeCheckError<'a> {
},
#[allow(dead_code)]
DoubleDefaultExport(SpanWithSource),
NoDefaultExport {
position: SpanWithSource,
partial_import_path: &'a str,
},
CannotOpenFile {
file: CouldNotOpenFile,
import_position: Option<SpanWithSource>,
Expand Down Expand Up @@ -685,6 +689,11 @@ impl From<TypeCheckError<'_>> for Diagnostic {
labels: vec![("Existing import with same name".to_string(), existing_position)],
},
TypeCheckError::DoubleDefaultExport(_) => todo!(),
TypeCheckError::NoDefaultExport { partial_import_path, position, ..} => Diagnostic::Position {
reason: format!("Cannot find default export from module '{partial_import_path}'"),
position,
kind
},
TypeCheckError::CannotOpenFile { file, import_position, possibles, partial_import_path } => if let Some(import_position) = import_position {
Diagnostic::PositionWithAdditionalLabels {
reason: format!("Cannot find {partial_import_path}"),
Expand Down
7 changes: 6 additions & 1 deletion checker/src/features/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ pub fn import_items<
);
}
} else {
todo!("emit 'no default export' diagnostic")
checking_data.diagnostics_container.add_error(
crate::diagnostics::TypeCheckError::NoDefaultExport {
position: position.with_source(current_source),
partial_import_path,
},
);
}
} else {
environment.register_variable_handle_error(
Expand Down

0 comments on commit 49eda2f

Please sign in to comment.