THRIFT-6333: Report an undefined typedef target before any generator runs - #3925
slachiewicz wants to merge 1 commit into
Conversation
…runs Client: compiler t_typedef::get_type() resolved a forward typedef on first use, from inside whichever generator asked first, and on a target that was never declared it printed to stdout and exited: files the earlier generators had written stayed on disk, the message carried no file or line, and a generator that never asked did not report it at all. get_type() now throws the message, and parse() resolves every type the program refers to (typedef chains, struct fields, constants, service signatures, through containers) before returning, so the error reaches failure() with the file and line before any generator runs. generate() already catches the same exception for anything a generator asks for later. No output changes for an input the compiler accepts; the audit mode, which never resolved typedefs, now rejects an undefined type it used to ignore. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Code reviewNo blocking issues found. Checked for bugs and CLAUDE.md compliance. Two suggestions, below the bar for an issue but verified:
thrift/compiler/cpp/src/thrift/main.cc Lines 1050 to 1054 in b5a7d62 thrift/compiler/cpp/src/thrift/main.cc Lines 937 to 959 in b5a7d62 thrift/compiler/cpp/src/thrift/parse/parse.cc Lines 29 to 35 in b5a7d62
🤖 Generated with Claude Code |
t_typedef::get_type()resolved a forward typedef on first use, from inside whichever generator asked first, and on a target that was never declared it printedType "X" not definedto stdout and calledexit(1): files the earlier generators had written stayed on disk (thrift --gen go --gen javaleftGoUnusedProtection__.go), the message carried no file or line, and a generator that never asked did not report it at all. https://issues.apache.org/jira/browse/THRIFT-6333get_type()now throws the message, andparse()resolves every type the program refers to — typedef chains, struct fields, constants, service signatures, through containers — before returning, so the error reachesfailure()as[FAILURE:file:line] Type "X" not definedon stderr before any generator runs.generate()already catches the same exception for anything a generator asks for later. The line is the one the parser is at when the pass ends (the file's last line plus one), since the parse tree keeps no line per declaration; the file is the useful part.Behaviour changes: none for an input the compiler accepts (over every
.thriftin the repository with--gen go --gen java --gen json -r: 159 files byte-identical, 35 rejected by both with the same status).--auditnow rejects an undefined type it used to ignore;test/audit/thrift_audit_test.plstill passes all 46 cases.Tests:
compiler/cpp/tests/cpp/t_cpp_parser_typedef_tests.ccchecks that an undefined target throws the message and that a typedef declared after its use resolves.THRIFT-NNNN:pattern