Skip to content
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

Improve MissingColonColon diagnostic. #5926

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/cairo-lang-semantic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ impl DiagnosticEntry for SemanticDiagnostic {
)
}
}
SemanticDiagnosticKind::MaybeMissingColonColon => "Are you missing a `::`?.".into(),
}
}

Expand Down Expand Up @@ -1141,6 +1142,7 @@ pub enum SemanticDiagnosticKind {
DerefCycle {
deref_chain: String,
},
MaybeMissingColonColon,
}

/// The kind of an expression with multiple possible return types.
Expand Down
33 changes: 33 additions & 0 deletions crates/cairo-lang-semantic/src/diagnostic_test_data/tests
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,36 @@ error: Cannot have array of type "()" that is zero sized.
--> lib.cairo:3:15
let _fail = array![()];
^********^

//! > ==========================================================================

//! > Test missing '::' in path.

//! > test_runner_name
test_expr_diagnostics(expect_diagnostics: true)

//! > expr_code
{
let _fail = bar<felt252>(1);
}

//! > module_code
fn bar<T>(_a: T) {}

//! > function_body

//! > expected_diagnostics
error: Expected variable or constant, found function.
--> lib.cairo:4:15
let _fail = bar<felt252>(1);
^*^

error: Are you missing a `::`?.
--> lib.cairo:4:18
let _fail = bar<felt252>(1);
^

error: Type annotations needed. Failed to infer ?0.
--> lib.cairo:4:15
let _fail = bar<felt252>(1);
^*************^
10 changes: 9 additions & 1 deletion crates/cairo-lang-semantic/src/expr/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use cairo_lang_defs::ids::{
use cairo_lang_diagnostics::{skip_diagnostic, Maybe, ToOption};
use cairo_lang_filesystem::ids::{FileKind, FileLongId, VirtualFile};
use cairo_lang_syntax::node::ast::{
BlockOrIf, ExprPtr, PatternListOr, PatternStructParam, UnaryOperator,
BinaryOperator, BlockOrIf, ExprPtr, PatternListOr, PatternStructParam, UnaryOperator,
};
use cairo_lang_syntax::node::db::SyntaxGroup;
use cairo_lang_syntax::node::helpers::{GetIdentifier, PathSegmentEx};
Expand Down Expand Up @@ -596,7 +596,15 @@ fn call_core_binary_op(
})?;

let mut lexpr = compute_expr_semantic(ctx, lhs_syntax);

if let (Expr::Missing(_), BinaryOperator::LT(_)) = (&lexpr.expr, &binary_op) {
return Err(ctx
.diagnostics
.report(binary_op.stable_ptr(), SemanticDiagnosticKind::MaybeMissingColonColon));
}

let mut rexpr = compute_expr_semantic(ctx, rhs_syntax);

ctx.reduce_ty(lexpr.ty()).check_not_missing(db)?;
ctx.reduce_ty(rexpr.ty()).check_not_missing(db)?;

Expand Down