Description
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:
- 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. - 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
.