Step 1990: Fix C++ struct field type loss and queue_ready test-files blocker
CppParser bug: declaration/field_declaration nodes created Variable AST nodes
but never extracted the "type" field from the tree-sitter parse tree. This
caused CppGeneratorTypes::inferFieldType to always fall back to
"auto /* TODO: specify type */" for struct fields whose names didn't match
name-based heuristics. Fix: read childByFieldName(member, "type"), create a
PrimitiveType child, and attach via var->setChild("type", ...) — same pattern
already used for function return types and parameters. Also unwrap
init_declarator nodes so field names are clean identifiers, not "x = 0".
queue_ready bug: strictExecutionContract mode blocked on missing testFiles
even when the project was starting new work and test files don't exist yet.
Demoted to a warning so new sprint work is not blocked on pre-declared tests.
5/5 tests passing (step1990_test).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -170,31 +170,26 @@ private:
|
||||
} else if (memberType == "function_definition") {
|
||||
auto* meth = convertCppMethodDecl(member, source, className, currentVisibility);
|
||||
if (meth) cls->addChild("methods", meth);
|
||||
} else if (memberType == "declaration") {
|
||||
// Could be a field declaration
|
||||
} else if (memberType == "declaration" || memberType == "field_declaration") {
|
||||
TSNode declNode = childByFieldName(member, "declarator");
|
||||
if (!ts_node_is_null(declNode)) {
|
||||
std::string fieldName = nodeText(declNode, source);
|
||||
auto* var = new Variable(IdGenerator::next("var"), fieldName);
|
||||
applySpan(var, member);
|
||||
cls->addChild("fields", var);
|
||||
} else {
|
||||
// Try to find field names from named children
|
||||
uint32_t dc = ts_node_named_child_count(member);
|
||||
for (uint32_t d = 0; d < dc; ++d) {
|
||||
TSNode dchild = ts_node_named_child(member, d);
|
||||
std::string dtype = nodeType(dchild);
|
||||
if (dtype == "field_identifier" || dtype == "identifier") {
|
||||
// Skip type specifiers — just get the last identifier-like thing
|
||||
}
|
||||
// The declarator may be an init_declarator (e.g. `x = 0`) — unwrap it.
|
||||
std::string declKind = nodeType(declNode);
|
||||
TSNode identNode = declNode;
|
||||
if (declKind == "init_declarator") {
|
||||
TSNode inner = childByFieldName(declNode, "declarator");
|
||||
if (!ts_node_is_null(inner)) identNode = inner;
|
||||
}
|
||||
}
|
||||
} else if (memberType == "field_declaration") {
|
||||
TSNode declNode = childByFieldName(member, "declarator");
|
||||
if (!ts_node_is_null(declNode)) {
|
||||
std::string fieldName = nodeText(declNode, source);
|
||||
std::string fieldName = nodeText(identNode, source);
|
||||
auto* var = new Variable(IdGenerator::next("var"), fieldName);
|
||||
applySpan(var, member);
|
||||
// Extract the declared type from the "type" field of the declaration node.
|
||||
TSNode typeNode = childByFieldName(member, "type");
|
||||
if (!ts_node_is_null(typeNode)) {
|
||||
std::string typeText = nodeText(typeNode, source);
|
||||
auto* fieldType = new PrimitiveType(IdGenerator::next("type"), typeText);
|
||||
var->setChild("type", fieldType);
|
||||
}
|
||||
cls->addChild("fields", var);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user