Skip to content

parser: missing comments, fmt removes comments between fields in map init with enum keys #18362

@ttytm

Description

@ttytm

Describe the bug

v fmt will remove comments between map fields in an enum-key map initialization.

Expected Behavior

Comments are preserved.

Current Behavior

Comments are removed.

Reproduction Steps

Format the following code

enum HttpHeader {
	user_agent
	referer
}

headers := {
	HttpHeader.user_agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
	// content_length: '17' // <-- will be deleted
	.referer:              'wwww.google.com'
	// content_length: '17' // <-- won't be deleted
}

Possible Solution

No response

Additional Information/Context

I couldn't fully isolate it but maybe that's a start:

"In-Between" comments are not contained in containers__map_init() anymore:

comments << p.eat_comments()

While the same comments are still present in the related parser__eat_comments() fn:

comments << p.comment()

V version

0.3.4

Environment details (OS name and version, etc.)

linux,arch;amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Unit: ParserBugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions