GitNexus/gitnexus/test/fixtures/lang-resolution/go-structural-interface-dispatch/repository.go
evolution 052319324d
Some checks failed
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
Devcontainer Smoke / Config-transform unit tests (push) Has been cancelled
Devcontainer Smoke / Build devcontainer image (push) Has been cancelled
feat(go): infer structural interface implementations (#1966)
2026-06-02 09:27:44 +01:00

102 lines
1.4 KiB
Go

package main
type User struct {
Name string
}
type Repository interface {
Find(id string) User
Save(user User) error
}
type SqlRepository struct{}
func (s SqlRepository) Find(id string) User {
return User{Name: id}
}
func (s SqlRepository) Save(user User) error {
return nil
}
type MemoryRepository struct{}
func (m MemoryRepository) Find(id string) User {
return User{Name: id}
}
func (m MemoryRepository) Save(user User) error {
return nil
}
type BadRepository struct{}
func (b BadRepository) Find(id string) User {
return User{Name: id}
}
func (b BadRepository) Save(id string) error {
return nil
}
func precise(user User) {
var repo Repository = SqlRepository{}
repo.Save(user)
}
func fallback(repo Repository, user User) {
repo.Save(user)
}
type Reader interface {
Read() error
}
type ReadCloser interface {
Reader
Close() error
}
type FileBase struct{}
func (f FileBase) Read() error {
return nil
}
type File struct {
FileBase
}
func (f File) Close() error {
return nil
}
type ShadowReadFile struct {
FileBase
}
func (s ShadowReadFile) Read(path string) error {
return nil
}
func (s ShadowReadFile) Close() error {
return nil
}
type CloseOnly struct{}
func (c CloseOnly) Close() error {
return nil
}
func fallbackReadCloser(rc ReadCloser) {
rc.Close()
}
type PointerOnly interface {
Touch()
}
type PointerOnlyThing struct{}
func (p *PointerOnlyThing) Touch() {}