feat: implement better error messages with 'Did you mean?' suggestions
Add Levenshtein distance-based similarity matching for undefined variables, unknown types, unknown effects, and unknown traits. When a name is not found, the error now suggests similar names within edit distance 2. Changes: - Add levenshtein_distance() function to diagnostics module - Add find_similar_names() and format_did_you_mean() helpers - Update typechecker to suggest similar names for: - Undefined variables - Unknown types - Unknown effects - Unknown traits - Add 17 new tests for similarity matching Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -1221,6 +1221,21 @@ c")"#;
|
||||
assert!(diag.hints.iter().any(|h| h.contains("spelling")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_undefined_variable_suggestion() {
|
||||
// Test that similar variable names are suggested
|
||||
let source = r#"
|
||||
let myVariable = 42
|
||||
let x = myVriable
|
||||
"#;
|
||||
let result = super::eval(source);
|
||||
assert!(result.is_err());
|
||||
let err = result.unwrap_err();
|
||||
// The error should contain a "Did you mean?" suggestion
|
||||
assert!(err.contains("Did you mean") || err.contains("myVariable"),
|
||||
"Error should suggest 'myVariable': {}", err);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_purity_violation_categorization() {
|
||||
let error = TypeError {
|
||||
|
||||
Reference in New Issue
Block a user