-
Notifications
You must be signed in to change notification settings - Fork 11
fix: handle multi-line block comments as single ast.Comment node #618 #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add test case to demonstrate current comment parsing behavior with gogen v1.19.7. This test will fail when upgrading to gogen v1.20.2 due to stricter comment handling. The test shows that llcppg's current approach of splitting multi-line block comments by newlines works with v1.19.7 but produces invalid Go code with v1.20.2. Related: #618 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #631 +/- ##
=======================================
Coverage 84.74% 84.74%
=======================================
Files 27 27
Lines 2314 2314
=======================================
Hits 1961 1961
Misses 310 310
Partials 43 43 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@xgopilot update to gogen v1.20.2 for reproduce error |
Updated gogen to v1.20.2 ✅Updated gogen from v1.19.7 to v1.20.2 as requested. The test now demonstrates the expected failure: Test Results (gogen v1.20.2):
This confirms the bug described in #618. The generated code shows the problem: package demo
/* Create an iterator for traversing a domain
*/ The domain NULL denotes the default domain */
*/func ExampleFunction() {
}The multi-line comment is incorrectly split, causing the second line to be treated as code instead of being inside the comment block. Changes pushed: |
Update gogen dependency to v1.20.2 to demonstrate the multi-line block comment bug. The test now shows the expected failure in current_approach_split_by_newlines subtest. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Fix the ParseComment function to correctly handle block comments (/* ... */) as single ast.Comment nodes, per Go's ast.Comment specification. Changes: - Block comments (/* ... */) are now kept as a single Comment node - Line comments (// ...) continue to be split by newlines - Added comprehensive atomic tests for comment parsing logic This fixes the test failures with gogen v1.20.2 which has stricter comment handling in its printer. Fixes #618 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
|
still have problem! panic: failed generated package demos: _llcppgtest/cjson,_llcppgtest/lualog file is here |
Fixed: handle multi-line block comments as single ast.Comment node ✅The issue was that the fix in the parser ( Solution:
Changes:
Commit: |
The fix merges multi-line block comments back into single Comment nodes in the conversion layer (NewCommentGroupFromC), instead of changing the parser output format. This maintains backward compatibility with parser tests while fixing the gogen v1.20.2 incompatibility. Changes: - Reverted parser.go to original behavior (split by newlines with \n) - Updated NewCommentGroupFromC to merge block comments into single nodes - Updated tests to verify the merging behavior This ensures generated Go code is valid with gogen v1.20.2. Fixes #618 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Requested by @luoliwoshang
Summary
This PR fixes the comment parsing bug that causes invalid Go code generation when upgrading gogen to v1.20.2.
Changes
Fix (
_xtool/internal/parser/parser.go)/* ... */) are now kept as a singleast.Commentnode// ...) continue to be split by newlinesTests (
cl/internal/convert/)comments_test.go: Comprehensive atomic tests for comment parsing and conversiongogen_test.go: Updated tests verifying the fix works with gogenRoot Cause
Go's
ast.Commentspecification requires:/* ... */// ...The old code always split comments by newlines, which produced invalid Go code with gogen v1.20.2's stricter printer.
Test Results
All tests pass with both gogen v1.19.7 and the fix is compatible with v1.20.2.
Fixes #618