Cannot package Go library with types that start with "new"
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 267
- Avg merge
- 1d 25m
- Merged PRs (30d)
- 14
Description
## :bug: Bug Report
### Affected Languages
- [ ] `TypeScript` or `Javascript`
- [ ] `Python`
- [ ] `Java`
- [ ] .NET (`C#`, `F#`, ...)
- [x] `Go`
### General Information
* **JSII Version:** 1.47.0 (build 86d2c33), typescript 3.9.10
* **Platform:** macOS 11.6.1
### What is the problem?
When I try packaging a jsii-based library into Go, I get an error saying that "NewProject has been redeclared in this block".
The issue seems to be that Go creates bindings for functions with "NewX" to construct instances of classes named X. This causes a conflict because I am exporting a class named `Project` and a struct named `NewProject`.
Since this is a necessary limitation of the go language bindings, I expected the JSII compiler to warn me during compiling when it sees that I have classes/structs/methods that start with the string "New". (I'm not sure if structs are the only case where this can happen or not).
Link to repo commit where this can be reproduced: https://github.com/projen/projen/tree/eb1283fbadd13d2d25fe977dbecabddab523bda8
### Verbose Log
```
[jsii-pacmak] [WARN] Failed building go
[jsii-pacmak] [WARN] go failed
Error: Command (go build -modfile local.go.mod ./...) failed with status 2:
#STDERR> # github.com/projen/projen-go/projen
#STDERR> ./projen.go:3923:6: NewProject redeclared in this block
#STDERR> /Volumes/workplace/projen/dist/go/projen/projen.go:3367:6: previous declaration
#STDERR> ./projen.init.go:520:18: invalid indirect of NewProject (type func(*ProjectOptions) Project)
#STDERR>
#STDOUT>
at ChildProcess. (/Volumes/workplace/projen/node_modules/jsii-pacmak/lib/util.js:119:27)
at Object.onceWrapper (node:events:514:26)
at ChildProcess.emit (node:events:394:28)
at maybeClose (node:internal/child_process:1064:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
```
Contributor guide
Research direction
Start with jsii-pacmak's Go generation and reproduce the failure using the linked projen commit and the reported `go build -modfile local.go.mod ./...` command. Done means the compiler warns about names that conflict with generated Go constructors before packaging fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, typescript
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100