diff --git a/ets2panda/lexer/scripts/keywords.yaml b/ets2panda/lexer/scripts/keywords.yaml index 08ae6869c9a8bf14d83b52ab027894a69cad3149..76a8f6c1621c85352020dd4cb4daffbc0221df7f 100644 --- a/ets2panda/lexer/scripts/keywords.yaml +++ b/ets2panda/lexer/scripts/keywords.yaml @@ -297,8 +297,7 @@ keywords: - name: 'in' token: KEYW_IN - keyword: [as, js, ts] - keyword_like: [ets] + keyword: [as, js, ets, ts] flags: [binary] - name: 'infer' diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 66ddcc044e8e2c478bf790a9923d043e37cef6ec..7cba7aa76a745c3e78b7bae5031094c69ac012bc 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -451,6 +451,10 @@ private: ir::Statement *ParseTopLevelDeclStatement(StatementParsingFlags flags); ir::Statement *ParseTopLevelStatement(); void ParseTrailingBlock([[maybe_unused]] ir::CallExpression *callExpr) override; + bool IsInOperatorTypeSupported() const override + { + return false; + } void CheckDeclare(); friend class ExternalSourceParser; diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 6d111ce34ace4c3348ba058e12bf2ad0e88774d0..a767e196f6cdc077959d8f906d3ef3eb0f4dc878 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -1336,6 +1336,13 @@ ir::Expression *ParserImpl::ParseBinaryExpression(ir::Expression *left, Expressi } ir::Expression *rightExpr = ParseExpressionOrTypeAnnotation(operatorType, ExpressionParseFlags::DISALLOW_YIELD); + + // NOTE(rsipka): 'in' operator is not supported but parsed the expression above for more detailed error reporting + if (operatorType == lexer::TokenType::KEYW_IN && !IsInOperatorTypeSupported()) { + LogError(diagnostic::UNSUPPORTED_IN_OPERATOR_TYPE); + return AllocBrokenExpression(lexer::SourceRange {left->Start(), rightExpr->End()}); + } + ir::ConditionalExpression *conditionalExpr = nullptr; if (rightExpr->IsConditionalExpression() && !rightExpr->IsGrouped()) { conditionalExpr = rightExpr->AsConditionalExpression(); diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index cd39352b1d1015be72c794a3ccb5842142086e0e..748a1a4e5c1f90ed4c524b4fbed7e428db88969f 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -167,6 +167,10 @@ protected: virtual void ParseTrailingBlock([[maybe_unused]] ir::CallExpression *callExpr) {} ir::Expression *CreateBinaryAssignmentExpression(ir::Expression *assignmentExpression, ir::Expression *lhsExpression, lexer::TokenType tokenType); + virtual bool IsInOperatorTypeSupported() const + { + return true; + } // StatementParser.Cpp diff --git a/ets2panda/test/ast/compiler/ets/keyof_invalid_argument.ets b/ets2panda/test/ast/compiler/ets/keyof_invalid_argument.ets index 5edd48126e4922f1439ab8a08ec0c2294b004999..e6d5bc837747fa835552cbabfa030552e7c11c6b 100644 --- a/ets2panda/test/ast/compiler/ets/keyof_invalid_argument.ets +++ b/ets2panda/test/ast/compiler/ets/keyof_invalid_argument.ets @@ -30,7 +30,7 @@ type NestedKey = T[K] extends object ? keyof T[K] : never; /* @@? 18:33 Error TypeError: The super type of 'ObservableImpl' class is not extensible. */ /* @@? 20:24 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 20:27 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ -/* @@? 20:31 Error SyntaxError: Field type annotation expected. */ +/* @@? 20:29 Error SyntaxError: Unexpected token 'in'. */ /* @@? 20:41 Error SyntaxError: Unexpected token '&'. */ /* @@? 20:41 Error SyntaxError: Unexpected token, expected ',' or ')'. */ /* @@? 20:41 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ diff --git a/ets2panda/test/ast/parser/ets/circular_type_in_alias.ets b/ets2panda/test/ast/parser/ets/circular_type_in_alias.ets index 09a0912afdb078b51efeb8e558a248d3b9c6d2fc..8a2229b5d76e5a7a5ebc064253bce13d5d2adfd6 100644 --- a/ets2panda/test/ast/parser/ets/circular_type_in_alias.ets +++ b/ets2panda/test/ast/parser/ets/circular_type_in_alias.ets @@ -20,7 +20,7 @@ type Loop> = { /* @@? 16:24 Error TypeError: Circular type alias reference */ /* @@? 16:38 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 17:6 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ -/* @@? 17:10 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:8 Error SyntaxError: Unexpected token 'in'. */ /* @@? 17:16 Error SyntaxError: Field type annotation expected. */ /* @@? 17:18 Error SyntaxError: Unexpected token ']'. */ /* @@? 17:18 Error SyntaxError: Field type annotation expected. */ diff --git a/ets2panda/test/ast/parser/ets/for_of_04.ets b/ets2panda/test/ast/parser/ets/for_of_04.ets index 0b51c9f55cf40b74822d6ecb8756c425f4897172..3ec38b614659751a0a742497f3f8d26524ec784c 100644 --- a/ets2panda/test/ast/parser/ets/for_of_04.ets +++ b/ets2panda/test/ast/parser/ets/for_of_04.ets @@ -34,5 +34,4 @@ for (i in 50) { /* @@? 20:21 Error TypeError: Unresolved reference a */ /* @@? 20:22 Error SyntaxError: Unexpected token ')'. */ /* @@? 20:24 Error SyntaxError: Unexpected token '{'. */ -/* @@? 25:11 Error TypeError: Object type doesn't have proper iterator method. */ -/* @@? 25:11 Error TypeError: 'For-of' statement source expression is not of iterable type. */ +/* @@? 25:8 Error SyntaxError: 'for ... in' loop is not supported, please use regular 'for' or 'for ... of ...' loop to iterate through arrays and iterable objects. */ diff --git a/ets2panda/test/ast/parser/ets/typenode_clone_comprehensive.ets b/ets2panda/test/ast/parser/ets/typenode_clone_comprehensive.ets index 069c51fb2f2b65c77959c4bb1af9b5001bce86c7..7a247f20567e20bf154a64019de3b27e5cdc68b0 100644 --- a/ets2panda/test/ast/parser/ets/typenode_clone_comprehensive.ets +++ b/ets2panda/test/ast/parser/ets/typenode_clone_comprehensive.ets @@ -89,7 +89,7 @@ declare const test3: ComplexType<'b'>; /* @@? 38:39 Error SyntaxError: Unexpected token ']'. */ /* @@? 41:19 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 41:22 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ -/* @@? 41:26 Error SyntaxError: Field type annotation expected. */ +/* @@? 41:24 Error SyntaxError: Unexpected token 'in'. */ /* @@? 41:32 Error SyntaxError: Field type annotation expected. */ /* @@? 41:43 Error SyntaxError: Unexpected token ']'. */ /* @@? 41:43 Error SyntaxError: Field type annotation expected. */ @@ -115,7 +115,7 @@ declare const test3: ComplexType<'b'>; /* @@? 61:30 Error SyntaxError: Unexpected token ','. */ /* @@? 62:13 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 62:16 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ -/* @@? 62:20 Error SyntaxError: Field type annotation expected. */ +/* @@? 62:18 Error SyntaxError: Unexpected token 'in'. */ /* @@? 62:22 Error SyntaxError: Unexpected token ']'. */ /* @@? 62:22 Error SyntaxError: Field type annotation expected. */ /* @@? 62:23 Error SyntaxError: Unexpected token ':'. */ diff --git a/ets2panda/test/runtime/ets/lambda_with_receiver/lambda_with_receiver_catch_outside_field.ets b/ets2panda/test/runtime/ets/lambda_with_receiver/lambda_with_receiver_catch_outside_field.ets index 4150edd9ddc61f5c869af61c85ae92bb64e56d8c..3bb0274da4e895b57e87668252401655359c2301 100644 --- a/ets2panda/test/runtime/ets/lambda_with_receiver/lambda_with_receiver_catch_outside_field.ets +++ b/ets2panda/test/runtime/ets/lambda_with_receiver/lambda_with_receiver_catch_outside_field.ets @@ -15,7 +15,7 @@ class C{ out: number = 0; - in: number = 0; + input: number = 0; data: number = 0; } @@ -23,7 +23,7 @@ function process1(con: (this:C)=>void){ let c = new C(); c.con(); arktest.assertEQ(c.out, 1); - arktest.assertEQ(c.in, 2); + arktest.assertEQ(c.input, 2); arktest.assertEQ(c.data, 3); } @@ -31,7 +31,7 @@ function process2(con: (this:C)=>void){ let c = new C(); c.con(); arktest.assertEQ(c.out, 1); - arktest.assertEQ(c.in, 2); + arktest.assertEQ(c.input, 2); arktest.assertEQ(c.data, 3); } @@ -41,14 +41,14 @@ function main(){ // passed lambda as parameter. process1((this:C):void => { this.out = field_out; - this.in = field_in; + this.input = field_in; this.data = 3; }) // passed lambda as trailing lambda. process2() { this.out = field_out; - this.in = field_in; + this.input = field_in; this.data = 3; } } \ No newline at end of file diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 2401da7d0e2450558426cb7d33c1c12f4a8a8e92..e5f3e99499fb7f52de16b5ff6e24684df6fa4587 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1259,6 +1259,10 @@ syntax: message: "Unsupported enum type annotation. Supported enum types are: int, long or double. String is allowed for literal\ \ types, not annotations." +- name: UNSUPPORTED_IN_OPERATOR_TYPE + id: 58212 + message: "The in operator is not supported in binary expression." + - name: UNTERMINATED_MULTI_LINE_COMMENT id: 245 message: "Unterminated multi-line comment."