diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 4764110d37d8f1992fd0984fe44cd8cf0f16c185..0f4a5490a0f6277dd529e15bfde1a00126d740d9 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -298,20 +298,16 @@ Type *ETSChecker::ResolveIdentifier(ir::Identifier *ident) if (resolved == nullptr) { resolved = ExtraCheckForResolvedError(ident); - if (resolved == nullptr) { - if (VarBinder()->GetScope()->IsClassScope() && this->IsAnyError()) { - return ident->SetTsType(GlobalTypeError()); - } - auto [decl, var] = VarBinder()->NewVarDecl( - ident->Start(), - !ident->IsErrorPlaceHolder() ? ident->Name() : compiler::GenName(ProgramAllocator()).View()); - var->SetScope(VarBinder()->GetScope()); - ident->SetVariable(var); - decl->BindNode(ident); - return ident->SetTsType(var->SetTsType(GlobalTypeError())); - } - ident->SetVariable(resolved); - return GetTypeOfVariable(resolved); + if (VarBinder()->GetScope()->IsClassScope() && this->IsAnyError()) { + return ident->SetTsType(GlobalTypeError()); + } + auto [decl, var] = VarBinder()->NewVarDecl( + ident->Start(), + !ident->IsErrorPlaceHolder() ? ident->Name() : compiler::GenName(ProgramAllocator()).View()); + var->SetScope(VarBinder()->GetScope()); + ident->SetVariable(var); + decl->BindNode(ident); + return ident->SetTsType(var->SetTsType(GlobalTypeError())); } ident->SetVariable(resolved); diff --git a/ets2panda/test/ast/compiler/ets/identifierReference17.ets b/ets2panda/test/ast/compiler/ets/identifierReference17.ets new file mode 100644 index 0000000000000000000000000000000000000000..760017c2b44101c43e347e544556adff7b75ae7c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/identifierReference17.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class FooClass { + foo(): number { + foo = 42; + return 1; + } +} + +/* @@? 18:9 Error TypeError: Property 'foo' must be accessed through 'this' */ diff --git a/ets2panda/test/ast/parser/ets/FixedArray/StringFasta.ets b/ets2panda/test/ast/parser/ets/FixedArray/StringFasta.ets index 87b568099bb05661d6a6599a853eb5fa09258647..b102e46ef20f352dc56d71834a8ac0ed7c406505 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/StringFasta.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/StringFasta.ets @@ -127,32 +127,12 @@ function main(): void { /* @@? 19:22 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 19:50 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 21:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 22:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 23:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 24:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 25:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 26:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 27:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 28:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 29:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 30:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 31:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 32:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 33:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 34:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 35:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ /* @@? 36:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 37:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 38:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 39:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@@ label Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ +/* @@? 41:26 Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ /* @@? 47:13 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ -/* @@? 47:21 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ /* @@? 47:28 Error TypeError: Static property 'A' must be accessed through it's class 'Random' */ /* @@? 47:32 Error TypeError: Static property 'C' must be accessed through it's class 'Random' */ /* @@? 47:37 Error TypeError: Static property 'M' must be accessed through it's class 'Random' */ -/* @@? 48:26 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ -/* @@? 48:33 Error TypeError: Static property 'M' must be accessed through it's class 'Random' */ /* @@? 52:35 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 53:27 Error TypeError: Type 'null' cannot be assigned to type 'Char' */ /* @@? 54:26 Error TypeError: Cannot find type 'HashMap'. */ @@ -168,11 +148,6 @@ function main(): void { /* @@? 95:65 Error TypeError: 'For-of' statement source expression is not of iterable type. */ /* @@? 103:20 Error TypeError: Type 'Double' has no call signatures. */ /* @@? 112:16 Error TypeError: Static property 'fastaRepeat' must be accessed through it's class 'StringFasta' */ -/* @@? 112:32 Error TypeError: Property 'count' must be accessed through 'this' */ /* @@? 113:16 Error TypeError: Static property 'fastaRandom' must be accessed through it's class 'StringFasta' */ -/* @@? 113:32 Error TypeError: Property 'count' must be accessed through 'this' */ -/* @@? 113:46 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 114:16 Error TypeError: Static property 'fastaRandom' must be accessed through it's class 'StringFasta' */ -/* @@? 114:32 Error TypeError: Property 'count' must be accessed through 'this' */ -/* @@? 114:46 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ +/* @@? 114:16 Error TypeError: This expression is not callable. */ /* @@? 116:36 Error TypeError: 'expected' is a static property of 'StringFasta' */ diff --git a/ets2panda/test/ast/parser/ets/InvalidClasses.ets b/ets2panda/test/ast/parser/ets/InvalidClasses.ets index 85d1c1fbf9e80b6d9045d25c5e6e0a15da8f7904..65bcbd26cf8fdd427efec64a67a6a0a2f6865a3c 100644 --- a/ets2panda/test/ast/parser/ets/InvalidClasses.ets +++ b/ets2panda/test/ast/parser/ets/InvalidClasses.ets @@ -83,6 +83,14 @@ interface I1 { /* @@? 17:20 Error TypeError: Only abstract or native methods can't have body. */ /* @@? 18:12 Error SyntaxError: Duplicated modifier is not allowed. */ /* @@? 18:30 Error TypeError: Native, Abstract and Declare methods cannot have body. */ +/* @@? 19:9 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Double): void` */ +/* @@? 19:9 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Boolean): void` */ +/* @@? 19:9 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Byte): void` */ +/* @@? 19:9 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Short): void` */ +/* @@? 19:9 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Char): void` */ +/* @@? 19:9 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Float): void` */ +/* @@? 19:9 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Int): void` */ +/* @@? 19:9 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Long): void` */ /* @@? 19:21 Error TypeError: Static property 'f' must be accessed through it's class 'A' */ /* @@? 22:12 Error SyntaxError: Access modifier must precede field and method modifiers. */ /* @@? 22:20 Error TypeError: Invalid method modifier(s): an abstract method can't have private, override, static, final or native modifier. */ @@ -98,10 +106,10 @@ interface I1 { /* @@? 45:5 Error SyntaxError: The special predefined method '$_set' should have exactly two required parameter. */ /* @@? 45:5 Error SyntaxError: The special predefined method '$_set' cannot be asynchronous. */ /* @@? 45:16 Error TypeError: Only abstract or native methods can't have body. */ -/* @@? 47:5 Error SyntaxError: The special predefined method '$_iterator' cannot be asynchronous. */ /* @@? 47:5 Error SyntaxError: The special predefined method '$_iterator' should not have parameters. */ -/* @@? 47:21 Error TypeError: The return type of '$_iterator' must be a type that implements Iterator interface. */ +/* @@? 47:5 Error SyntaxError: The special predefined method '$_iterator' cannot be asynchronous. */ /* @@? 47:21 Error TypeError: Return type of async function must be 'Promise'. */ +/* @@? 47:21 Error TypeError: The return type of '$_iterator' must be a type that implements Iterator interface. */ /* @@? 54:21 Error TypeError: Initializers are not allowed in ambient contexts: x */ /* @@? 54:23 Error SyntaxError: Initializers are not allowed in ambient contexts. */ /* @@? 58:9 Error SyntaxError: Unexpected token 'native'. */ @@ -116,9 +124,9 @@ interface I1 { /* @@? 66:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ /* @@? 66:18 Error SyntaxError: Private interface methods must have body. */ /* @@? 67:9 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 67:16 Error SyntaxError: Identifier expected. */ /* @@? 67:16 Error SyntaxError: Unexpected token, expected ','. */ /* @@? 67:16 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 67:16 Error SyntaxError: Identifier expected. */ /* @@? 67:24 Error SyntaxError: Private interface methods must have body. */ /* @@? 72:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ /* @@? 72:13 Error SyntaxError: Interface fields must have type annotation. */ diff --git a/ets2panda/test/ast/parser/ets/StringFasta.ets b/ets2panda/test/ast/parser/ets/StringFasta.ets index 3292dd0c41902d1c734be12991833b084c986dea..10ab839bf433135b74ee80aebe4b7549fbd926d7 100644 --- a/ets2panda/test/ast/parser/ets/StringFasta.ets +++ b/ets2panda/test/ast/parser/ets/StringFasta.ets @@ -127,32 +127,12 @@ function main(): void { /* @@? 19:22 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 19:50 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 21:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 22:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 23:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 24:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 25:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 26:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 27:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 28:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 29:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 30:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 31:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 32:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 33:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 34:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 35:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ /* @@? 36:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 37:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 38:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 39:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@@ label Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ +/* @@? 41:26 Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ /* @@? 47:13 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ -/* @@? 47:21 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ /* @@? 47:28 Error TypeError: Static property 'A' must be accessed through it's class 'Random' */ /* @@? 47:32 Error TypeError: Static property 'C' must be accessed through it's class 'Random' */ /* @@? 47:37 Error TypeError: Static property 'M' must be accessed through it's class 'Random' */ -/* @@? 48:26 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ -/* @@? 48:33 Error TypeError: Static property 'M' must be accessed through it's class 'Random' */ /* @@? 52:35 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 53:27 Error TypeError: Type 'null' cannot be assigned to type 'Char' */ /* @@? 54:26 Error TypeError: Cannot find type 'HashMap'. */ @@ -168,11 +148,6 @@ function main(): void { /* @@? 95:65 Error TypeError: 'For-of' statement source expression is not of iterable type. */ /* @@? 103:20 Error TypeError: Type 'Double' has no call signatures. */ /* @@? 112:16 Error TypeError: Static property 'fastaRepeat' must be accessed through it's class 'StringFasta' */ -/* @@? 112:32 Error TypeError: Property 'count' must be accessed through 'this' */ /* @@? 113:16 Error TypeError: Static property 'fastaRandom' must be accessed through it's class 'StringFasta' */ -/* @@? 113:32 Error TypeError: Property 'count' must be accessed through 'this' */ -/* @@? 113:46 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 114:16 Error TypeError: Static property 'fastaRandom' must be accessed through it's class 'StringFasta' */ -/* @@? 114:32 Error TypeError: Property 'count' must be accessed through 'this' */ -/* @@? 114:46 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ +/* @@? 114:16 Error TypeError: This expression is not callable. */ /* @@? 116:36 Error TypeError: 'expected' is a static property of 'StringFasta' */