Skip to content

Commit

Permalink
Improve MissingColonColon diagnostic.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalesokhin-starkware committed Jul 1, 2024
1 parent a471991 commit 37645bd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
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::MissingColonColon => "Are you missing a `::`?.".into(),
}
}

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

/// 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::MissingColonColon));
}

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

0 comments on commit 37645bd

Please sign in to comment.