Skip to content
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
49 changes: 40 additions & 9 deletions crates/compiler/src/error_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@ pub enum ErrorCode {
E303,
/// Signal parameter type mismatch in emit_signal
E304,
/// Invalid lifecycle function signature
E305,
// Future semantic errors:
// E305: Unreachable code
// E306: Unused variable (warning)
// E302: Unused function (warning)
// E303: Dead code (warning)
// E304: Invalid break/continue (not in loop)
// E305: Invalid return (not in function)
// E306: Unreachable code
// E307: Unused variable (warning)
// E308: Unused function (warning)
// E309: Dead code (warning)
// E310: Invalid break/continue (not in loop)
// E311: Invalid return (not in function)

// Runtime Errors (E400-E499)
/// Division by zero
Expand Down Expand Up @@ -249,6 +251,7 @@ impl ErrorCode {
ErrorCode::E302 => "E302",
ErrorCode::E303 => "E303",
ErrorCode::E304 => "E304",
ErrorCode::E305 => "E305",

// Runtime Errors
ErrorCode::E400 => "E400",
Expand Down Expand Up @@ -373,6 +376,7 @@ impl ErrorCode {
ErrorCode::E302 => "Signal not defined",
ErrorCode::E303 => "Signal parameter count mismatch",
ErrorCode::E304 => "Signal parameter type mismatch",
ErrorCode::E305 => "Invalid lifecycle function signature",

// Runtime Errors
ErrorCode::E400 => "Division by zero",
Expand Down Expand Up @@ -443,9 +447,11 @@ impl ErrorCode {
| ErrorCode::E219 => ErrorCategory::Type,

// Semantic Errors
ErrorCode::E301 | ErrorCode::E302 | ErrorCode::E303 | ErrorCode::E304 => {
ErrorCategory::Semantic
}
ErrorCode::E301
| ErrorCode::E302
| ErrorCode::E303
| ErrorCode::E304
| ErrorCode::E305 => ErrorCategory::Semantic,

// Runtime Errors
ErrorCode::E400
Expand Down Expand Up @@ -652,4 +658,29 @@ mod tests {
println!("E200 URL: {}", url);
assert!(url.contains("#e200-type-mismatch"));
}

#[test]
fn test_all_semantic_errors() {
// Test semantic error codes (E301-E305) including lifecycle validation
let codes = vec![
ErrorCode::E301,
ErrorCode::E302,
ErrorCode::E303,
ErrorCode::E304,
ErrorCode::E305,
];
for code in codes {
assert_eq!(code.category(), ErrorCategory::Semantic);
assert!(!code.as_str().is_empty());
assert!(!code.description().is_empty());
}

// Specifically test E305 (lifecycle function signature validation)
assert_eq!(ErrorCode::E305.as_str(), "E305");
assert_eq!(
ErrorCode::E305.description(),
"Invalid lifecycle function signature"
);
assert_eq!(ErrorCode::E305.category(), ErrorCategory::Semantic);
}
}
16 changes: 16 additions & 0 deletions crates/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,20 @@ mod tests {
let source = std::fs::read_to_string(example_path("reload.ferris")).unwrap();
assert!(compile(&source).is_ok());
}

// Phase 2 example tests temporarily disabled - files deferred due to compilation investigation
// See: docs/planning/v0.0.4/KNOWN_LIMITATIONS.md#-known-issues
// Core functionality verified through unit tests (test_input_function_valid, etc.)

// #[test]
// fn test_compile_input() {
// let source = std::fs::read_to_string(example_path("input.ferris")).unwrap();
// assert!(compile(&source).is_ok());
// }

// #[test]
// fn test_compile_callbacks() {
// let source = std::fs::read_to_string(example_path("callbacks.ferris")).unwrap();
// assert!(compile(&source).is_ok());
// }
}
Loading