Jens Geyer created THRIFT-6240:
----------------------------------
Summary: Go client does not compile when a service function has an
argument named p
Key: THRIFT-6240
URL: https://issues.apache.org/jira/browse/THRIFT-6240
Project: Thrift
Issue Type: Bug
Components: Go - Compiler
Affects Versions: 0.24.0
Reporter: Jens Geyer
Every generated Go client method uses {{p}} as its receiver. A function
argument that is also called {{p}} becomes a second name {{p}} in the same
method, and the package does not compile.
{noformat}
namespace go parg
struct Item {
1: i32 id
}
service PService {
void withString(1: string p),
void withStruct(1: Item p),
}
{noformat}
The generated client method:
{noformat}
func (p *PServiceClient) WithString(ctx context.Context, p string) (_err error)
{
{noformat}
In a Go module named {{exp}}:
{noformat}
$ thrift -out gen --gen go:package_prefix=exp/gen/ PArg.thrift
$ go build ./gen/parg
gen/parg/PArg.go:217:58: p redeclared in this block
gen/parg/PArg.go:217:7: other declaration of p
gen/parg/PArg.go:219:13: cannot use p (variable of type *PServiceClient) as
string value in assignment
gen/parg/PArg.go:232:58: p redeclared in this block
gen/parg/PArg.go:232:7: other declaration of p
gen/parg/PArg.go:234:13: cannot use p (variable of type *PServiceClient) as
*Item value in assignment
{noformat}
The type of the argument does not matter.
{{lib/go/test/ConflictArgNamesTest.thrift}} covers other argument names that
collide with generated code ({{result}}, {{meta}}, {{r}}, {{err}}), but not
{{p}}.
Reproduced with 0.24.0 and current master.
_Drafted with AI assistance (Claude Opus 5); reviewed and posted by Jens Geyer._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)