diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-28 13:36:16 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-28 13:36:16 +0000 |
| commit | b28384fed1ce638e8b00b72dba974e9fd7e55eb4 (patch) | |
| tree | b0b342b148c1d5b33197f7a59d0a7a7edb92af1c /lib/Parser/ParserFunction.cc | |
| parent | caa88a9b36d9e1dfae40ecb31aee05bc2891fa17 (diff) | |
feat(overload): support default return types
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/Parser/ParserFunction.cc')
| -rw-r--r-- | lib/Parser/ParserFunction.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Parser/ParserFunction.cc b/lib/Parser/ParserFunction.cc index 8f3a117..2f80c42 100644 --- a/lib/Parser/ParserFunction.cc +++ b/lib/Parser/ParserFunction.cc @@ -203,8 +203,13 @@ std::unique_ptr<FunctionDefAST> Parser::ParseFunction(const std::string &OwnerCl if (!Args) return nullptr; std::string RetType = "INTEGER"; + bool IsDefaultReturn = false; if (CurTok == tok_returns) { getNextToken(); + if (CurTok == tok_default) { + IsDefaultReturn = true; + getNextToken(); + } if (CurTok == tok_array) { cps::sourceError(Lex.getLine(), "A FUNCTION cannot RETURN an array; use a BYREF PROCEDURE parameter instead"); return nullptr; @@ -218,8 +223,14 @@ std::unique_ptr<FunctionDefAST> Parser::ParseFunction(const std::string &OwnerCl auto Proto = std::make_unique<PrototypeAST>(Name, std::move(*Args), RetType, false, OwnerClass, IsPublic, IsOverload); Proto->setOperator(Operator); + Proto->setDefaultReturn(IsDefaultReturn); - return ParseFunctionBody(std::move(Proto), tok_endfunction, "expected ENDFUNCTION", Line); + auto Def = ParseFunctionBody(std::move(Proto), tok_endfunction, "expected ENDFUNCTION", Line); + if (IsDefaultReturn && !CurrentTemplate.empty()) { + sourceError(Line, "DEFAULT return types are not supported in templates"); + return nullptr; + } + return Def; } std::unique_ptr<FunctionDefAST> Parser::ParseProcedure(const std::string &OwnerClass, bool IsPublic, bool IsOverload) { |
