diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 2b6e9ce4816286d4105e555eacad3119d6577124..16bf14af95381d0bacf177ff450ce27d6c9c2612 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -967,6 +967,11 @@ FunctionSignature ParserImpl::ParseFunctionSignature(ParserStatus status) { ir::TSTypeParameterDeclaration *typeParamDecl = ParseFunctionTypeParameters(); + // Check if constructor has type parameters + if ((status & ParserStatus::CONSTRUCTOR_FUNCTION) != 0 && typeParamDecl != nullptr) { + LogError(diagnostic::CONSTRUCTOR_TYPE_PARAMETERS); + } + if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS) { auto parameter = (status & ParserStatus::ARROW_FUNCTION) != 0 ? ParseFunctionParameter() : nullptr; if (parameter != nullptr) { diff --git a/ets2panda/test/ast/parser/ets/type_variance2.ets b/ets2panda/test/ast/parser/ets/type_variance2.ets index 67d7a48464199ebb03ddf3328a46bac9afb687b6..c7b077b0b6d2ae67d8c467c912f2edf81e0ec8e9 100644 --- a/ets2panda/test/ast/parser/ets/type_variance2.ets +++ b/ets2panda/test/ast/parser/ets/type_variance2.ets @@ -18,3 +18,4 @@ class C { } /* @@@ label Error SyntaxError: Variance modifier is not allowed here. */ +/* @@? 17:35 Error SyntaxError: Constructor should not have type parameters. */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index a998b7eacc637388b76862e1f7d1c186d3e43878..6076e39373ab57339bf49b114b694ecb3928da6b 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -137,6 +137,10 @@ syntax: id: 127 message: "Conflicting modifiers '!' and '?' on field." +- name: CONSTRUCTOR_TYPE_PARAMETERS + id: 329 + message: "Constructor should not have type parameters." + - name: DECALRE_IN_AMBIENT_CONTEXT id: 104 message: "A 'declare' modifier cannot be used in an already ambient context." @@ -423,8 +427,8 @@ syntax: - name: IMPORT_TOP_LEVEL id: 226 - message: "Import declarations can only be used on the top level and before any other declaration, top level statement or - directive." + message: "Import declarations can only be used on the top level and before any other declaration, top level statement or\ + \ directive." - name: IMPROPER_NESTING_CLASS id: 233 @@ -460,8 +464,8 @@ syntax: - name: INIT_MODULE_DECLARATION_POSITION id: 322 - message: "initModule() must only be called immediately after the import statement, and before any other declarations or - statements." + message: "initModule() must only be called immediately after the import statement, and before any other declarations or\ + \ statements." - name: INSERT_NODE_ABSENT id: 10 @@ -541,8 +545,8 @@ syntax: - name: INVALID_DECORATOR_CONSTRUCTOR id: 201 - message: "The modifier for a constructor should be limited to access modifiers (private, internal, protected, public), and - 'native' modifiers." + message: "The modifier for a constructor should be limited to access modifiers (private, internal, protected, public), and\ + \ 'native' modifiers." - name: INVALID_DESTRUCTURING_TARGET id: 49 @@ -710,8 +714,8 @@ syntax: - name: LITERAL_VALUE_IDENT id: 315 - message: "Number, string or computed value property name '{}' is not allowed, use classes to access data by property names - that are identifiers" + message: "Number, string or computed value property name '{}' is not allowed, use classes to access data by property names\ + \ that are identifiers" - name: LOCAL_CLASS_ACCESS_MOD id: 30 @@ -1203,8 +1207,8 @@ syntax: - name: UNSUPPORTED_ENUM_TYPE id: 327 - message: "Unsupported enum type annotation. Supported enum types are: int, long or double. String is allowed for literal - types, not annotations." + message: "Unsupported enum type annotation. Supported enum types are: int, long or double. String is allowed for literal\ + \ types, not annotations." - name: UNTERMINATED_MULTI_LINE_COMMENT id: 245