diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index 7c0bd342e97a317106119b561437caf824eb9ed6..9763da93e64c6202c785b53644755927a4e6d561 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -584,7 +584,10 @@ ir::Expression *ETSParser::ParsePotentialAsExpression(ir::Expression *primaryExp { ES2PANDA_ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::KEYW_AS); Lexer()->NextToken(); - + if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CONST) { + LogError(diagnostic::AS_CONST_USAGE); + return nullptr; + } TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::REPORT_ERROR | TypeAnnotationParsingOptions::ANNOTATION_NOT_ALLOW; ir::TypeNode *type = ParseTypeAnnotation(&options); diff --git a/ets2panda/test/ast/parser/ets/string_literal_const_cast.ets b/ets2panda/test/ast/parser/ets/string_literal_const_cast.ets index 899f906944c3522294dfcdd5cb5f2c9b43feada2..d265e8555759d3a03bc205f29f3fe93f97c5d11f 100644 --- a/ets2panda/test/ast/parser/ets/string_literal_const_cast.ets +++ b/ets2panda/test/ast/parser/ets/string_literal_const_cast.ets @@ -15,7 +15,7 @@ let x = "literal str" as const -/* @@? 16:26 Error SyntaxError: Invalid Type. */ +/* @@? 16:26 Error SyntaxError: 'as const' assertion is not supported. */ /* @@? 16:26 Error SyntaxError: Unexpected token 'const'. */ /* @@? 23:1 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 23:1 Error SyntaxError: Variable must be initialized or it's type must be declared. */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index a412c35ab549ada14459b3f41c431bdf0075ed09..864602db43dd4ab9980bc3a7edca0ad15f25e34f 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1230,4 +1230,8 @@ syntax: - name: DEEP_NESTING id: 305 - message: "Maximum allowed nesting level exceeded." \ No newline at end of file + message: "Maximum allowed nesting level exceeded." + +- name: AS_CONST_USAGE + id: 306 + message: "'as const' assertion is not supported." \ No newline at end of file