fn declaration adjustments

This commit is contained in:
Nilton Constantino
2026-01-29 15:45:48 +00:00
parent b814a6c48d
commit 9de23475f6
14 changed files with 90 additions and 13 deletions
@@ -197,7 +197,7 @@ impl Parser {
let start_span = self.consume(TokenKind::Fn)?.span;
let name = self.expect_identifier()?;
let params = self.parse_param_list()?;
let ret = if self.peek().kind == TokenKind::Arrow {
let ret = if self.peek().kind == TokenKind::Colon {
self.advance();
Box::new(self.parse_type_ref()?)
} else {
@@ -275,7 +275,7 @@ impl Parser {
let start_span = self.consume(TokenKind::Fn)?.span;
let name = self.expect_identifier()?;
let params = self.parse_param_list()?;
let _ret = if self.peek().kind == TokenKind::Arrow {
let _ret = if self.peek().kind == TokenKind::Colon {
self.advance();
Some(Box::new(self.parse_type_ref()?))
} else {
@@ -31,7 +31,7 @@ import math from "./math.pbs";
#[test]
fn test_parse_fn_decl() {
let source = r#"
fn add(a: int, b: int) -> int {
fn add(a: int, b: int): int {
return a + b;
}
"#;
@@ -71,7 +71,7 @@ fn test_parse_service_decl() {
let source = r#"
pub service Audio {
fn play(sound: Sound);
fn stop() -> bool;
fn stop(): bool;
}
"#;
let mut parser = Parser::new(source, 0);
@@ -21,7 +21,7 @@ fn test_compile_hip_program() {
// Create main.pbs with HIP effects
let code = "
fn main() {
fn frame(): void {
let x = alloc int;
mutate x as v {
let y = v + 1;
@@ -20,7 +20,7 @@ fn test_golden_bytecode_snapshot() {
let code = r#"
declare contract Gfx host {}
fn helper(val: int) -> int {
fn helper(val: int): int {
return val * 2;
}
@@ -7,7 +7,7 @@ use prometeu_compiler::ir_core;
#[test]
fn test_basic_lowering() {
let code = "
fn add(a: int, b: int) -> int {
fn add(a: int, b: int): int {
return a + b;
}
fn main() {
@@ -43,7 +43,7 @@ fn test_basic_lowering() {
#[test]
fn test_control_flow_lowering() {
let code = "
fn max(a: int, b: int) -> int {
fn max(a: int, b: int): int {
if (a > b) {
return a;
} else {
@@ -36,7 +36,7 @@ fn test_type_mismatch_let() {
#[test]
fn test_type_mismatch_return() {
let code = "fn main() -> int { return \"hello\"; }";
let code = "fn main(): int { return \"hello\"; }";
let res = check_code(code);
assert!(res.is_err());
assert!(res.unwrap_err().contains("E_TYPE_MISMATCH"));
@@ -57,7 +57,7 @@ fn test_type_mismatch_call() {
#[test]
fn test_missing_return_path() {
let code = "fn foo() -> int { if (true) { return 1; } }";
let code = "fn foo(): int { if (true) { return 1; } }";
let res = check_code(code);
assert!(res.is_err());
assert!(res.unwrap_err().contains("E_TYPE_RETURN_PATH"));
@@ -65,7 +65,7 @@ fn test_missing_return_path() {
#[test]
fn test_implicit_none_optional() {
let code = "fn foo() -> optional<int> { if (true) { return some(1); } }";
let code = "fn foo(): optional<int> { if (true) { return some(1); } }";
let res = check_code(code);
if let Err(e) = &res { println!("Error: {}", e); }
assert!(res.is_ok()); // Implicit none allowed for optional
@@ -82,7 +82,7 @@ fn test_valid_optional_assignment() {
#[test]
fn test_valid_result_usage() {
let code = "
fn foo() -> result<int, string> {
fn foo(): result<int, string> {
if (true) {
return ok(10);
} else {
@@ -160,7 +160,7 @@ fn test_struct_type_usage() {
fn test_service_type_usage() {
let code = "
pub service MyService {
fn hello(name: string) -> void
fn hello(name: string): void
}
fn foo(s: MyService) {}
";