Skip to content

Parser: potential to mismatch options to functions declared in non-alphabetical order #29

Closed
@switchupcb

Description

@switchupcb

Problem

Specifying functions in non-alphabetical order can result in comment-options being mismatched to function options.

Reason

The go/types Interface.Method() function returns the "i'th method of interface t ... ordered by their unique Id.". In contrast, Copygen option-comments are parsed by AST in order of declaration. As a result, assigning using i (where i is 0) results in the comment for the first declared function being assigned to the first alphabetically ordered function, and so on and so forth for subsequent positions (1,2,3,...). These are NOT necessarily equivalent which results in the issue where a function is assigned a mismatched option.

A side effect of this behavior is that Copygen always outputs functions in alphabetical order.

Solution

There are two possible solutions:

  1. Do NOT use alphabetical order (which entails finding a different method to iterate over go/types interface methods). This will change the Copygen output to be non-alphabetical as opposed to the non-intended alphabetical order.
  2. Keep alphabetical order and re-work comments to be assigned alphabetically. This will maintain the current alphabetically-ordered function output; albeit unintended.

Implementing 1 entails setting i to the declared position and modifying the order of access to the go/types Copygen interface. Implementing 2 entails setting i to the "unique" (alphabetical) position and modifying the order of access to the ast Copygen Interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    edge caseAn error occurred.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions