From 0e8bc8c3e806796bf3b03e7da6c59ff24e58559f Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 15:17:34 +0000 Subject: fix(parser): parse casts to type names from other source files Co-Authored-By: Claude Sonnet 5.5 --- lib/Parser/ParserExpression.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/Parser') diff --git a/lib/Parser/ParserExpression.cc b/lib/Parser/ParserExpression.cc index b75f704..f41694f 100644 --- a/lib/Parser/ParserExpression.cc +++ b/lib/Parser/ParserExpression.cc @@ -196,6 +196,21 @@ std::unique_ptr Parser::ParseParenExpr() { getNextToken(); bool IsType = isBuiltinTypeToken(CurTok) || (CurTok == tok_identifier && TypeNames.count(Lex.IdentifierStr)); + // A type declared in another source file is unknown here, so `( IDENT )` + // directly followed on the same line by the start of a primary is also a + // cast. `+` and `-` stay binary: `(n) - 5` is arithmetic. + if (!IsType && CurTok == tok_identifier && Lex.peekToken(0) == ')' && + Lex.peekLine(1) == Lex.peekLine(0)) { + switch (Lex.peekToken(1)) { + case tok_identifier: case tok_number_int: case tok_number_real: + case tok_string_literal: case tok_c_string_literal: case tok_char_literal: + case tok_true: case tok_false: case '(': case tok_not: + IsType = true; + break; + default: + break; + } + } if (IsType) { std::string TypeName = ParseTypeName(); if (TypeName.empty()) return nullptr; -- cgit v1.3.1-4-g156e