diff --git a/Ast/src/Parser.cpp b/Ast/src/Parser.cpp index 9bcdea32..e3139576 100644 --- a/Ast/src/Parser.cpp +++ b/Ast/src/Parser.cpp @@ -1574,6 +1574,12 @@ AstTypeOrPack Parser::parseSimpleTypeAnnotation(bool allowPack) else return {reportTypeAnnotationError(begin, {}, /*isMissing*/ false, "String literal contains malformed escape sequence")}; } + else if (lexer.current().type == Lexeme::InterpStringBegin || lexer.current().type == Lexeme::InterpStringEnd) + { + parseInterpString(); + + return {reportTypeAnnotationError(begin, {}, /*isMissing*/ false, "Interpolated string literals cannot be used as types")}; + } else if (lexer.current().type == Lexeme::BrokenString) { Location location = lexer.current().location; diff --git a/tests/Parser.test.cpp b/tests/Parser.test.cpp index 96b1c94c..1cc31d49 100644 --- a/tests/Parser.test.cpp +++ b/tests/Parser.test.cpp @@ -1117,14 +1117,18 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_as_type_fail") try { parse(R"( - local a: `what` = `what` + local a: `what` = `???` + local b: `what {"the"}` = `???` + local c: `what {"the"} heck` = `???` )"); FAIL("Expected ParseErrors to be thrown"); } - catch (const ParseErrors& e) + catch (const ParseErrors& parseErrors) { - // CHECK_EQ("Interpolated strings cannot be used alone to call a function. Wrap this in parentheses.", e.getErrors().front().getMessage()); - CHECK_EQ("TODO", e.getErrors().front().getMessage()); + CHECK_EQ(parseErrors.getErrors().size(), 3); + + for (ParseError error : parseErrors.getErrors()) + CHECK_EQ(error.getMessage(), "Interpolated string literals cannot be used as types"); } }