Skip to content

wire: UX can be better by supporting argument name matching warning during wire check #93

Open
@garukun

Description

@garukun

Problem

Considering the following scenario:

// in app.go
type Agent1 struct {
  name string
}

type Agent2 struct {
  version string
}

type Server struct {
 A1 Agent1
 A2 Agent2
}

var set  = wire.NewSet(provideServer, provideAgent1, provideAgent2)

func provideServer(a1 *Agent1, a2 *Agent2) *Server {
  return &Server{A1: a1, A2: a2}
}

func provideAgent1(name string) *Agent1 {
  return  &App{name: name}
}

func provideAgent2(version string) *Agent2 {
  return &Agent{version: version}
}

// in injector.go
func Initialize(name string) {
  wire.Build(set)
}

wire check and wire gen completes just fine. While by the argument name, name and version means different things, both will actually be injected with the value of name. While I believe this is a user error and can be fixed using named types, UX can improve here.

Suggestion

While running wire check or wire gen, in addition to checking for colliding data types, also checks for distinct parameter names on colliding data types. In the added case, we output a warning message (with suggestions to use type alias) while allowing the code generation to complete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions