-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Go: Expose whether functions are variadic in their pp() output #17360
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
Go: Expose whether functions are variadic in their pp() output #17360
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, seems like a sensible change. One suggestion for improvement, if you are so inclined: perhaps it would make sense to put the [variadic]
inside the func( ... )
part, rather than after the return types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Why not copy how being variadic is normally shown in go signatures, i.e. func(...interface { }) int, error
? It's a bit more involved to remove the []
from the last parameter type, but it would be easier for everyone to understand (who is familiar with go).
go/ql/lib/semmle/go/Types.qll
Outdated
exists(string suffix | (if this.isVariadic() then suffix = " [variadic]" else suffix = "") | | ||
result = | ||
"func(" + concat(int i, Type tp | tp = this.getParameterType(i) | tp.pp(), ", " order by i) + | ||
") " + concat(int i, Type tp | tp = this.getResultType(i) | tp.pp(), ", " order by i) + | ||
suffix | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exists(string suffix | (if this.isVariadic() then suffix = " [variadic]" else suffix = "") | | |
result = | |
"func(" + concat(int i, Type tp | tp = this.getParameterType(i) | tp.pp(), ", " order by i) + | |
") " + concat(int i, Type tp | tp = this.getResultType(i) | tp.pp(), ", " order by i) + | |
suffix | |
) | |
result = | |
"func(" + | |
concat(int i, Type tp, string prefix | | |
if i = this.getNumParameter() - 1 and this.isVariadic() | |
then | |
tp = this.getParameterType(i).(SliceType).getElementType() and | |
prefix = "..." | |
else ( | |
tp = this.getParameterType(i) and | |
prefix = "" | |
) | |
| | |
prefix + tp.pp(), ", " order by i | |
) + ") " + concat(int i, Type tp | tp = this.getResultType(i) | tp.pp(), ", " order by i) |
This implements printing "...interface{ }" as I suggested in my previous review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you could also keep the [variadic]
to highlight variadic functions.
0c9fb70
to
d673d24
Compare
Actually, this should probably have a change note. I guess people might be pretty printing functions and be surprised that the output changes. |
Because |
This avoids our having types that are distinct both in the database and are distinguishable in QL, but which pretty-print identically.