Skip to content

Commit d64cf50

Browse files
committed
Correção na função check_test_function_stmt
Alterado lookup_function -> lookup_test Alterado map_function -> map_test
1 parent d28184c commit d64cf50

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

src/type_checker/statement_type_checker.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,27 +333,24 @@ fn check_test_function_stmt(
333333
function: Function,
334334
env: &Environment<Type>,
335335
) -> Result<Environment<Type>, ErrorMessage> {
336-
if env.lookup_function(&function.name).is_some() {
337-
return Err(format!("[Type Error] Test function '{}' already exists", function.name));
336+
if env.lookup_test(&function.name).is_some() {
337+
return Err(format!("[Type Error] Test function '{}' already exists.", function.name));
338338
}
339339
if !function.params.is_empty() {
340-
return Err("[Type Error] Test functions must not have parameters".into());
340+
return Err("[Type Error] Test functions must not have parameters.".into());
341341
}
342342
if function.kind != Type::TVoid {
343-
return Err("[Type Error] Test functions must return void".into());
343+
return Err("[Type Error] Test functions must return void.".into());
344344
}
345345

346-
let mut new_env = env.clone();
347-
new_env.push();
348-
349346
if let Some(body) = function.body.clone() {
350-
new_env = check_stmt(*body, &new_env)?;
347+
let mut scoped_env = env.clone();
348+
scoped_env.push();
349+
check_stmt(*body, &scoped_env)?;
351350
}
352351

353-
new_env.pop();
354-
355352
let mut final_env = env.clone();
356-
final_env.map_function(function);
353+
final_env.map_test(function);
357354
Ok(final_env)
358355
}
359356

@@ -981,9 +978,26 @@ mod tests {
981978
name: "valid_function".to_string(),
982979
kind: Type::TVoid,
983980
params: vec![],
984-
body: None,
981+
body: Some(Box::new(Block(vec![
982+
// 1. Declaramos as variáveis localmente
983+
Statement::VarDeclaration("a".to_string(), Box::new(Expression::CInt(10))),
984+
Statement::VarDeclaration("b".to_string(), Box::new(Expression::CInt(5))),
985+
986+
// 2. Usamos AssertEQ para verificar o resultado
987+
Statement::AssertEQ(
988+
// Expressão: a + b
989+
Box::new(Expression::Add(
990+
Box::new(Expression::Var("a".to_string())),
991+
Box::new(Expression::Var("b".to_string()))
992+
)),
993+
// Valor esperado: 15
994+
Box::new(Expression::CInt(15)),
995+
// Mensagem de erro
996+
Box::new(Expression::CString("A soma de 10 + 5 deveria ser 15".to_string()))
997+
)
998+
]))),
985999
});
986-
1000+
9871001
assert!(check_stmt(stmt, &env).is_ok());
9881002
}
9891003

0 commit comments

Comments
 (0)