diff --git a/src/torque/ast.h b/src/torque/ast.h index d8c6942743..5650ed418f 100644 --- a/src/torque/ast.h +++ b/src/torque/ast.h @@ -915,7 +915,7 @@ struct ClassDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(ClassDeclaration) ClassDeclaration(SourcePosition pos, Identifier* name, bool is_extern, bool generate_print, bool transient, - base::Optional super, + base::Optional super, base::Optional generates, std::vector methods, std::vector fields) @@ -924,7 +924,7 @@ struct ClassDeclaration : Declaration { is_extern(is_extern), generate_print(generate_print), transient(transient), - super(std::move(super)), + super(super), generates(std::move(generates)), methods(std::move(methods)), fields(std::move(fields)) {} @@ -932,7 +932,7 @@ struct ClassDeclaration : Declaration { bool is_extern; bool generate_print; bool transient; - base::Optional super; + base::Optional super; base::Optional generates; std::vector methods; std::vector fields; diff --git a/src/torque/declaration-visitor.cc b/src/torque/declaration-visitor.cc index fa3a147f2c..60ed1933c8 100644 --- a/src/torque/declaration-visitor.cc +++ b/src/torque/declaration-visitor.cc @@ -278,9 +278,7 @@ void DeclarationVisitor::Visit(ClassDeclaration* decl) { if (!decl->super) { ReportError("Extern class must extend another type."); } - // Compute the offset of the class' first member. If the class extends - // another class, it's the size of the extended class, otherwise zero. - const Type* super_type = Declarations::LookupType(*decl->super); + const Type* super_type = Declarations::GetType(*decl->super); if (super_type != TypeOracle::GetTaggedType()) { const ClassType* super_class = ClassType::DynamicCast(super_type); if (!super_class) { diff --git a/src/torque/torque-parser.cc b/src/torque/torque-parser.cc index 5ee6e2eee3..ce1b4bdf85 100644 --- a/src/torque/torque-parser.cc +++ b/src/torque/torque-parser.cc @@ -575,7 +575,7 @@ base::Optional MakeClassDeclaration( if (!IsValidTypeName(name->value)) { NamingConventionError("Type", name->value, "UpperCamelCase"); } - auto extends = child_results->NextAs>(); + auto extends = child_results->NextAs>(); auto generates = child_results->NextAs>(); auto methods = child_results->NextAs>(); auto fields = child_results->NextAs>(); @@ -1650,7 +1650,7 @@ struct TorqueGrammar : Grammar { MakeExternConstDeclaration), Rule({CheckIf(Token("@generatePrint")), CheckIf(Token("extern")), CheckIf(Token("transient")), Token("class"), &name, - Optional(Sequence({Token("extends"), &identifier})), + Optional(Sequence({Token("extends"), &type})), Optional( Sequence({Token("generates"), &externalString})), Token("{"), List(&method), diff --git a/test/unittests/torque/ls-server-data-unittest.cc b/test/unittests/torque/ls-server-data-unittest.cc index e462595839..b8af940759 100644 --- a/test/unittests/torque/ls-server-data-unittest.cc +++ b/test/unittests/torque/ls-server-data-unittest.cc @@ -79,6 +79,23 @@ TEST(LanguageServer, GotoTypeDefinitionNoDataForFile) { EXPECT_FALSE(LanguageServerData::FindDefinition(test_id, {0, 0})); } +TEST(LanguageServer, GotoDefinitionClassSuperType) { + const std::string source = + "type void;\n" + "type never;\n" + "type Tagged generates 'TNode' constexpr 'ObjectPtr';\n" + "extern class HeapObject extends Tagged {}"; + + TestCompiler compiler; + compiler.Compile(source); + + // Find the definition for 'Tagged' of the 'extends' on line 3. + const SourceId id = SourceFileMap::GetSourceId(""); + auto maybe_position = LanguageServerData::FindDefinition(id, {3, 33}); + ASSERT_TRUE(maybe_position.has_value()); + EXPECT_EQ(*maybe_position, (SourcePosition{id, {2, 5}, {2, 11}})); +} + } // namespace torque } // namespace internal } // namespace v8