From b59c573fab5671ce69c3e5766153c80ea1728e76 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Mon, 22 Apr 2024 17:24:41 +0100 Subject: [PATCH] Remove unused error variant --- compiler-core/src/analyse/imports.rs | 8 ++----- compiler-core/src/error.rs | 34 ++------------------------- compiler-core/src/type_/error.rs | 17 ++++---------- compiler-core/src/type_/expression.rs | 4 ++-- 4 files changed, 10 insertions(+), 53 deletions(-) diff --git a/compiler-core/src/analyse/imports.rs b/compiler-core/src/analyse/imports.rs index dfe17f06b28..0e79d4dffd0 100644 --- a/compiler-core/src/analyse/imports.rs +++ b/compiler-core/src/analyse/imports.rs @@ -78,9 +78,7 @@ impl<'a> Importer<'a> { name: import.name.clone(), module_name: module.name.clone(), type_constructors: module.public_type_names(), - imported_type_as_value: module - .get_public_value(&import.name) - .map_or_else(|| false, |_| true), + value_with_same_name: module.get_public_value(&import.name).is_some(), })? .clone() .with_location(import.location); @@ -124,9 +122,7 @@ impl<'a> Importer<'a> { name: import_name.clone(), module_name: module.name.clone(), value_constructors: module.public_value_names(), - imported_value_as_type: module - .get_public_type(import_name) - .map_or_else(|| false, |_| true), + type_with_same_name: module.get_public_type(import_name).is_some(), }); } }; diff --git a/compiler-core/src/error.rs b/compiler-core/src/error.rs index 30da2b1351e..7240220fb98 100644 --- a/compiler-core/src/error.rs +++ b/compiler-core/src/error.rs @@ -1912,7 +1912,7 @@ Private types can only be used within the module that defines them.", name, module_name, type_constructors, - imported_type_as_value + value_with_same_name: imported_type_as_value } => { let text = if *imported_type_as_value { format!("`{name}` is only a value, it cannot be imported as a type.") @@ -1945,7 +1945,7 @@ Private types can only be used within the module that defines them.", name, module_name, value_constructors, - imported_value_as_type, + type_with_same_name: imported_value_as_type, } => { let text = if *imported_value_as_type { format!("`{name}` is only a type, it cannot be imported as a value.") @@ -1973,36 +1973,6 @@ Private types can only be used within the module that defines them.", } } - TypeError::UnknownModuleField { - location, - name, - module_name, - type_constructors, - value_constructors, - } => { - let options: Vec<_> = type_constructors - .iter() - .chain(value_constructors) - .cloned() - .collect(); - let text = format!("The module `{module_name}` does not have a `{name}` field.",); - Diagnostic { - title: "Unknown module field".into(), - text, - hint: None, - level: Level::Error, - location: Some(Location { - label: Label { - text: did_you_mean(name, &options), - span: *location, - }, - path: path.clone(), - src: src.clone(), - extra_labels: vec![], - }), - } - } - TypeError::IncorrectNumClausePatterns { location, expected, diff --git a/compiler-core/src/type_/error.rs b/compiler-core/src/type_/error.rs index 4f1b135a611..6d1278227c4 100644 --- a/compiler-core/src/type_/error.rs +++ b/compiler-core/src/type_/error.rs @@ -69,7 +69,7 @@ pub enum Error { name: EcoString, module_name: EcoString, type_constructors: Vec, - imported_type_as_value: bool, + value_with_same_name: bool, }, UnknownModuleValue { @@ -77,15 +77,7 @@ pub enum Error { name: EcoString, module_name: EcoString, value_constructors: Vec, - imported_value_as_type: bool, - }, - - UnknownModuleField { - location: SrcSpan, - name: EcoString, - module_name: EcoString, - value_constructors: Vec, - type_constructors: Vec, + type_with_same_name: bool, }, NotFn { @@ -555,7 +547,6 @@ impl Error { | Error::UnknownModule { location, .. } | Error::UnknownModuleType { location, .. } | Error::UnknownModuleValue { location, .. } - | Error::UnknownModuleField { location, .. } | Error::NotFn { location, .. } | Error::UnknownRecordField { location, .. } | Error::IncorrectArity { location, .. } @@ -700,7 +691,7 @@ pub fn convert_get_value_constructor_error( name, module_name, value_constructors, - imported_value_as_type, + type_with_same_name: imported_value_as_type, }, } } @@ -761,7 +752,7 @@ pub fn convert_get_type_constructor_error( name, module_name, type_constructors, - imported_type_as_value, + value_with_same_name: imported_type_as_value, }, } } diff --git a/compiler-core/src/type_/expression.rs b/compiler-core/src/type_/expression.rs index 389f43e173f..4a7c92d4ff4 100644 --- a/compiler-core/src/type_/expression.rs +++ b/compiler-core/src/type_/expression.rs @@ -1627,7 +1627,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { }, module_name: module.name.clone(), value_constructors: module.public_value_names(), - imported_value_as_type: false, + type_with_same_name: false, })?; // Emit a warning if the value being used is deprecated. @@ -1959,7 +1959,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { module_name: module_name.clone(), name: name.clone(), value_constructors: module.public_value_names(), - imported_value_as_type: false, + type_with_same_name: false, })? } };