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

Failable types -> failable functions #642

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/modules/function/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl SyntaxModule<ParserMetadata> for FunctionDeclaration {
// Parse the body
token(meta, "{")?;
let (index_begin, index_end, is_failable) = skip_function_body(meta, declared_failable, &returns_tok)?;
if (!is_failable) && declared_failable {
if !is_failable && declared_failable {
return error!(meta, returns_tok, "Infallible functions must not have a '?' after the type name");
b1ek marked this conversation as resolved.
Show resolved Hide resolved
}
// Create a new context with the function body
Expand Down
6 changes: 5 additions & 1 deletion src/modules/function/declaration_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ use crate::utils::cc_flags::{CCFlags, get_ccflag_name};
use crate::utils::context::Context;
use crate::utils::function_interface::FunctionInterface;

pub fn skip_function_body(meta: &mut ParserMetadata, declared_failable: bool, returns_tok: &Option<Token>) -> Result<(usize, usize, bool), Failure> {
pub fn skip_function_body(
meta: &mut ParserMetadata,
declared_failable: bool,
returns_tok: &Option<Token>
b1ek marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<(usize, usize, bool), Failure> {
let index_begin = meta.get_index();
let mut is_failable = false;
let mut scope = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/function/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl SyntaxModule<ParserMetadata> for FunctionInvocation {
self.is_failable = function_unit.is_failable;
if self.is_failable {
match syntax(meta, &mut self.failed) {
Ok(_) => {},
Ok(_) => (),
Err(Failure::Quiet(_)) => return error!(meta, tok => {
message: "This function can fail. Please handle the failure",
comment: "You can use '?' in the end to propagate the failure"
Expand Down
Loading