-
-
Notifications
You must be signed in to change notification settings - Fork 873
Add suggestions for variables with the same name in imported modules when unknown variable #4810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
490e07a
0c73f82
9f9ae93
0e9d8a8
5f92807
8879a5e
0c30c19
0ea266c
8345a55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2402,9 +2402,9 @@ but no type in scope with that name." | |
discarded_location, | ||
name, | ||
type_with_name_in_scope, | ||
possible_modules, | ||
} => { | ||
let title = String::from("Unknown variable"); | ||
|
||
if let Some(ignored_location) = discarded_location { | ||
let location = Location { | ||
label: Label { | ||
|
@@ -2434,17 +2434,27 @@ but no type in scope with that name." | |
let text = if *type_with_name_in_scope { | ||
wrap_format!("`{name}` is a type, it cannot be used as a value.") | ||
} else { | ||
let is_first_char_uppercase = | ||
name.chars().next().is_some_and(char::is_uppercase); | ||
|
||
if is_first_char_uppercase { | ||
let mut text = if name.starts_with(char::is_uppercase) { | ||
wrap_format!( | ||
"The custom type variant constructor \ | ||
`{name}` is not in scope here." | ||
"The custom type variant constructor `{name}` is not in scope here." | ||
) | ||
} else { | ||
} | ||
else { | ||
wrap_format!("The name `{name}` is not in scope here.") | ||
}; | ||
|
||
// If there are some suggestions about public values in imported | ||
// modules put a "did you mean" text after the main message | ||
if !possible_modules.is_empty() { | ||
let mut did_you_mean_text = String::from("Did you mean one of these:\n\n"); | ||
for module_name in possible_modules { | ||
did_you_mean_text.push_str(&format!(" - {module_name}.{name}\n")); | ||
} | ||
text.push('\n'); | ||
text.push_str(&did_you_mean_text); | ||
|
||
} | ||
|
||
text | ||
}; | ||
|
||
Diagnostic { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1103,6 +1103,15 @@ impl ModuleInterface { | |||||
} | ||||||
} | ||||||
|
||||||
pub fn get_public_function(&self, name: &str, arity: usize) -> Option<&ValueConstructor> { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document this function please 🙏 Does this return internal values too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this function also return internal values. This is based on the function Also gonna document this function but |
||||||
self.get_public_value(name).filter(|value_constructor| { | ||||||
match value_constructor.type_.fn_types() { | ||||||
Some((fn_arguments_type, _)) => fn_arguments_type.len() == arity, | ||||||
None => false, | ||||||
} | ||||||
}) | ||||||
} | ||||||
|
||||||
pub fn get_public_type(&self, name: &str) -> Option<&TypeConstructor> { | ||||||
let type_ = self.types.get(name)?; | ||||||
if type_.publicity.is_importable() { | ||||||
|
@@ -1680,6 +1689,15 @@ pub enum FieldAccessUsage { | |||||
Other, | ||||||
} | ||||||
|
||||||
/// This is used to know when a value is used as a call or not. | ||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||||||
pub enum ValueUsage { | ||||||
/// Used as `call(..)`, `Type(..)`, `left |> right` or `left |> right(..)` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It's not a type, it's value, specifically a record. |
||||||
Call { arity: usize }, | ||||||
/// Used as `variable` | ||||||
Other, | ||||||
} | ||||||
|
||||||
/// Verify that a value is suitable to be used as a main function. | ||||||
fn assert_suitable_main_function( | ||||||
value: &ValueConstructor, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this entry needs to be updated with the latest wording of the error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, had not spotted that !