From 12ca7c5bb0d17e87199c95817a9d47023ba441d4 Mon Sep 17 00:00:00 2001 From: Kampfkarren Date: Tue, 26 Jul 2022 19:48:09 -0700 Subject: [PATCH] Better error for `constant` --- Ast/src/Parser.cpp | 5 +++++ tests/Parser.test.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Ast/src/Parser.cpp b/Ast/src/Parser.cpp index 6a0edd77..b86409cc 100644 --- a/Ast/src/Parser.cpp +++ b/Ast/src/Parser.cpp @@ -2213,6 +2213,11 @@ AstExpr* Parser::parseSimpleExpr() nextLexeme(); return reportExprError(start, {}, ERROR_INVALID_INTERP_DOUBLE_BRACE); } + else if (lexer.current().type == Lexeme::BrokenInterpNoFormat) + { + nextLexeme(); + return reportExprError(start, {}, "Interpolated strings must contain expressions, and cannot be constant"); + } else if (lexer.current().type == Lexeme::Dot3) { if (functionStack.back().vararg) diff --git a/tests/Parser.test.cpp b/tests/Parser.test.cpp index e0fe1d0f..d112d80a 100644 --- a/tests/Parser.test.cpp +++ b/tests/Parser.test.cpp @@ -1075,7 +1075,7 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_format") } catch (const ParseErrors& e) { - CHECK_EQ("Expected identifier when parsing expression, got interpolated string with no formatting", e.getErrors().front().getMessage()); + CHECK_EQ("Interpolated strings must contain expressions, and cannot be constant", e.getErrors().front().getMessage()); } }