Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// For the Provide path, we verify that constructorNodes produce at least one value,
// otherwise the function will never be called.
type constructorNode struct {
ctor interface{}
ctor any
ctype reflect.Type

// Location where this function was defined.
Expand Down Expand Up @@ -76,13 +76,13 @@ type constructorOptions struct {
// belong to the specified value group or implement any of the interfaces.
ResultName string
ResultGroup string
ResultAs []interface{}
ResultAs []any
Location *digreflect.Func
Callback Callback
BeforeCallback BeforeCallback
}

func newConstructorNode(ctor interface{}, s *Scope, origS *Scope, opts constructorOptions) (*constructorNode, error) {
func newConstructorNode(ctor any, s *Scope, origS *Scope, opts constructorOptions) (*constructorNode, error) {
cval := reflect.ValueOf(ctor)
ctype := cval.Type()
cptr := cval.Pointer()
Expand Down
2 changes: 1 addition & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type containerStore interface {
containerWriter

// Adds a new graph node to the Container
newGraphNode(w interface{}, orders map[*Scope]int)
newGraphNode(w any, orders map[*Scope]int)

// Returns a slice containing all known types.
knownTypes() []reflect.Type
Expand Down
8 changes: 4 additions & 4 deletions decorate.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type decorator interface {
}

type decoratorNode struct {
dcor interface{}
dcor any
dtype reflect.Type

id dot.CtorID
Expand Down Expand Up @@ -73,7 +73,7 @@ type decoratorNode struct {
beforeCallback BeforeCallback
}

func newDecoratorNode(dcor interface{}, s *Scope, opts decorateOptions) (*decoratorNode, error) {
func newDecoratorNode(dcor any, s *Scope, opts decorateOptions) (*decoratorNode, error) {
dval := reflect.ValueOf(dcor)
dtype := dval.Type()
dptr := dval.Pointer()
Expand Down Expand Up @@ -203,7 +203,7 @@ type DecorateInfo struct {
// Decorate provides a decorator for a type that has already been provided in the Container.
// Decorations at this level affect all scopes of the container.
// See Scope.Decorate for information on how to use this method.
func (c *Container) Decorate(decorator interface{}, opts ...DecorateOption) error {
func (c *Container) Decorate(decorator any, opts ...DecorateOption) error {
return c.scope.Decorate(decorator, opts...)
}

Expand Down Expand Up @@ -244,7 +244,7 @@ func (c *Container) Decorate(decorator interface{}, opts ...DecorateOption) erro
// Decorating a Scope affects all the child scopes of this Scope.
//
// Similar to a provider, the decorator function gets called *at most once*.
func (s *Scope) Decorate(decorator interface{}, opts ...DecorateOption) error {
func (s *Scope) Decorate(decorator any, opts ...DecorateOption) error {
var options decorateOptions
for _, opt := range opts {
opt.apply(&options)
Expand Down
28 changes: 14 additions & 14 deletions dig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ func TestRecoverFromPanic(t *testing.T) {
tests := []struct {
name string
setup func(*digtest.Container)
invoke interface{}
invoke any
wantErr []string
}{
{
Expand Down Expand Up @@ -1885,7 +1885,7 @@ func TestProvideConstructorErrors(t *testing.T) {

tests := []struct {
desc string
constructor interface{}
constructor any
msg string
}{
{
Expand Down Expand Up @@ -2005,7 +2005,7 @@ func TestCantProvideObjects(t *testing.T) {

var writer io.Writer = &bytes.Buffer{}
tests := []struct {
object interface{}
object any
typeDesc string
}{
{&bytes.Buffer{}, "pointer"},
Expand Down Expand Up @@ -2115,7 +2115,7 @@ func TestProvideInvalidAs(t *testing.T) {

tests := []struct {
name string
param interface{}
param any
expectedErr string
addlOption dig.ProvideOption
}{
Expand Down Expand Up @@ -2261,7 +2261,7 @@ func TestCantProvideUntypedNil(t *testing.T) {
func TestCantProvideErrorLikeType(t *testing.T) {
t.Parallel()

tests := []interface{}{
tests := []any{
func() *os.PathError { return &os.PathError{} },
func() error { return &os.PathError{} },
func() (*os.PathError, error) { return &os.PathError{}, nil },
Expand Down Expand Up @@ -2314,7 +2314,7 @@ func TestCantProvideParameterObjects(t *testing.T) {
func TestProvideKnownTypesFails(t *testing.T) {
t.Parallel()

provideArgs := []interface{}{
provideArgs := []any{
func() *bytes.Buffer { return nil },
func() (*bytes.Buffer, error) { return nil, nil },
}
Expand Down Expand Up @@ -2648,7 +2648,7 @@ func TestTypeCheckingEquality(t *testing.T) {
B
}
tests := []struct {
item interface{}
item any
isIn bool
isOut bool
}{
Expand Down Expand Up @@ -2743,7 +2743,7 @@ func testProvideFailures(t *testing.T, dryRun bool) {
A2: A{idx: 2},
A3: A{idx: 3},
}
}, dig.As(new(interface{})))
}, dig.As(new(any)))
require.Error(t, err, "provide must return error")
dig.AssertErrorMatches(t, err,
`cannot provide function "go.uber.org/dig_test".testProvideFailures\S+`,
Expand Down Expand Up @@ -3370,8 +3370,8 @@ func testInvokeFailures(t *testing.T, dryRun bool) {

cases := []struct {
name string
provide interface{}
invoke interface{}
provide any
invoke any
errContains []string
}{
{
Expand Down Expand Up @@ -3455,8 +3455,8 @@ func testInvokeFailures(t *testing.T, dryRun bool) {

cases := []struct {
name string
provide interface{}
invoke interface{}
provide any
invoke any
errContains []string
}{
{
Expand Down Expand Up @@ -3540,8 +3540,8 @@ func testInvokeFailures(t *testing.T, dryRun bool) {

cases := []struct {
name string
provide interface{}
invoke interface{}
provide any
invoke any
errContains []string
}{
{
Expand Down
2 changes: 1 addition & 1 deletion error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestRootCauseEndToEnd(t *testing.T) {
tests := []struct {
desc string
setup func(c *Container)
invoke interface{}
invoke any
wantAsDigError bool
wantRootCauseMessage string
wantRootCauseAsDigError bool
Expand Down
6 changes: 3 additions & 3 deletions graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import "go.uber.org/dig/internal/graph"

// graphNode is a single node in the dependency graph.
type graphNode struct {
Wrapped interface{}
Wrapped any
}

// graphHolder is the dependency graph of the container.
Expand Down Expand Up @@ -78,7 +78,7 @@ func (gh *graphHolder) EdgesFrom(u int) []int {
}

// NewNode adds a new value to the graph and returns its order.
func (gh *graphHolder) NewNode(wrapped interface{}) int {
func (gh *graphHolder) NewNode(wrapped any) int {
order := len(gh.nodes)
gh.nodes = append(gh.nodes, &graphNode{
Wrapped: wrapped,
Expand All @@ -88,7 +88,7 @@ func (gh *graphHolder) NewNode(wrapped interface{}) int {

// Lookup retrieves the value for the node with the given order.
// Lookup panics if i is invalid.
func (gh *graphHolder) Lookup(i int) interface{} {
func (gh *graphHolder) Lookup(i int) any {
return gh.nodes[i].Wrapped
}

Expand Down
6 changes: 3 additions & 3 deletions inout.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func isError(t reflect.Type) bool {
//
// See the documentation for dig.In for a comprehensive list of supported
// tags.
func IsIn(o interface{}) bool {
func IsIn(o any) bool {
return embedsType(o, _inType)
}

Expand All @@ -108,12 +108,12 @@ func IsIn(o interface{}) bool {
//
// See the documentation for dig.Out for a comprehensive list of supported
// tags.
func IsOut(o interface{}) bool {
func IsOut(o any) bool {
return embedsType(o, _outType)
}

// Returns true if t embeds e or if any of the types embedded by t embed e.
func embedsType(i interface{}, e reflect.Type) bool {
func embedsType(i any, e reflect.Type) bool {
// TODO: this function doesn't consider e being a pointer.
// given `type A foo { *In }`, this function would return false for
// embedding dig.In, which makes for some extra error checking in places
Expand Down
2 changes: 1 addition & 1 deletion internal/digerror/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// BugPanicf panics with the provided message directing users to GitHub issues
// creation page.
func BugPanicf(msg string, args ...interface{}) {
func BugPanicf(msg string, args ...any) {
panic(fmt.Sprintf("It looks like you have found a bug in dig. "+
"Please file an issue at https://github.com/uber-go/dig/issues/new "+
"and provide the following message: "+
Expand Down
2 changes: 1 addition & 1 deletion internal/digreflect/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (f *Func) Format(w fmt.State, c rune) {

// InspectFunc inspects and returns runtime information about the given
// function.
func InspectFunc(function interface{}) *Func {
func InspectFunc(function any) *Func {
fptr := reflect.ValueOf(function).Pointer()
return InspectFuncPC(fptr)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/digreflect/func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestInspectFunc(t *testing.T) {

tests := []struct {
desc string
give interface{}
give any
wantName string
wantPackage string

Expand Down
12 changes: 6 additions & 6 deletions internal/digtest/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,47 @@ func New(t testing.TB, opts ...dig.Option) *Container {

// RequireProvide provides the given function to the container,
// halting the test if it fails.
func (c *Container) RequireProvide(f interface{}, opts ...dig.ProvideOption) {
func (c *Container) RequireProvide(f any, opts ...dig.ProvideOption) {
c.t.Helper()

require.NoError(c.t, c.Provide(f, opts...), "failed to provide")
}

// RequireProvide provides the given function to the scope,
// halting the test if it fails.
func (s *Scope) RequireProvide(f interface{}, opts ...dig.ProvideOption) {
func (s *Scope) RequireProvide(f any, opts ...dig.ProvideOption) {
s.t.Helper()

require.NoError(s.t, s.Provide(f, opts...), "failed to provide")
}

// RequireInvoke invokes the given function to the container,
// halting the test if it fails.
func (c *Container) RequireInvoke(f interface{}, opts ...dig.InvokeOption) {
func (c *Container) RequireInvoke(f any, opts ...dig.InvokeOption) {
c.t.Helper()

require.NoError(c.t, c.Invoke(f, opts...), "failed to invoke")
}

// RequireInvoke invokes the given function to the scope,
// halting the test if it fails.
func (s *Scope) RequireInvoke(f interface{}, opts ...dig.InvokeOption) {
func (s *Scope) RequireInvoke(f any, opts ...dig.InvokeOption) {
s.t.Helper()

require.NoError(s.t, s.Invoke(f, opts...), "failed to invoke")
}

// RequireDecorate decorates the scope using the given function,
// halting the test if it fails.
func (c *Container) RequireDecorate(f interface{}, opts ...dig.DecorateOption) {
func (c *Container) RequireDecorate(f any, opts ...dig.DecorateOption) {
c.t.Helper()

require.NoError(c.t, c.Decorate(f, opts...), "failed to decorate")
}

// RequireDecorate decorates the scope using the given function,
// halting the test if it fails.
func (s *Scope) RequireDecorate(f interface{}, opts ...dig.DecorateOption) {
func (s *Scope) RequireDecorate(f any, opts ...dig.DecorateOption) {
s.t.Helper()

require.NoError(s.t, s.Decorate(f, opts...), "failed to decorate")
Expand Down
4 changes: 2 additions & 2 deletions invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (o fillInvokeInfoOption) applyInvokeOption(opts *invokeOptions) {
// If the [RecoverFromPanics] option was given to the container and a panic
// occurs when invoking, a [PanicError] with the panic contained will be
// returned. See [PanicError] for more info.
func (c *Container) Invoke(function interface{}, opts ...InvokeOption) error {
func (c *Container) Invoke(function any, opts ...InvokeOption) error {
return c.scope.Invoke(function, opts...)
}

Expand All @@ -91,7 +91,7 @@ func (c *Container) Invoke(function interface{}, opts ...InvokeOption) error {
//
// The function may return an error to indicate failure. The error will be
// returned to the caller as-is.
func (s *Scope) Invoke(function interface{}, opts ...InvokeOption) (err error) {
func (s *Scope) Invoke(function any, opts ...InvokeOption) (err error) {
ftype := reflect.TypeOf(function)
if ftype == nil {
return newErrInvalidInput("can't invoke an untyped nil", nil)
Expand Down
2 changes: 1 addition & 1 deletion param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestParamObjectFailure(t *testing.T) {
func TestParamGroupSliceErrors(t *testing.T) {
tests := []struct {
desc string
shape interface{}
shape any
wantErr string
}{
{
Expand Down
12 changes: 6 additions & 6 deletions provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type provideOptions struct {
Name string
Group string
Info *ProvideInfo
As []interface{}
As []any
Location *digreflect.Func
Exported bool
Callback Callback
Expand Down Expand Up @@ -259,11 +259,11 @@ func (o fillProvideInfoOption) applyProvideOption(opts *provideOptions) {
//
// This option cannot be provided for constructors which produce result
// objects.
func As(i ...interface{}) ProvideOption {
func As(i ...any) ProvideOption {
return provideAsOption(i)
}

type provideAsOption []interface{}
type provideAsOption []any

func (o provideAsOption) String() string {
buf := bytes.NewBufferString("As(")
Expand Down Expand Up @@ -380,7 +380,7 @@ type provider interface {
//
// Provide accepts argument types or dig.In structs as dependencies, and
// separate return values or dig.Out structs for results.
func (c *Container) Provide(constructor interface{}, opts ...ProvideOption) error {
func (c *Container) Provide(constructor any, opts ...ProvideOption) error {
return c.scope.Provide(constructor, opts...)
}

Expand All @@ -403,7 +403,7 @@ func (c *Container) Provide(constructor interface{}, opts ...ProvideOption) erro
// Scopes that are descendents, but not ancestors of this Scope.
// To provide a constructor to all the Scopes available, provide it to
// Container, which is the root Scope.
func (s *Scope) Provide(constructor interface{}, opts ...ProvideOption) error {
func (s *Scope) Provide(constructor any, opts ...ProvideOption) error {
ctype := reflect.TypeOf(constructor)
if ctype == nil {
return newErrInvalidInput("can't provide an untyped nil", nil)
Expand Down Expand Up @@ -437,7 +437,7 @@ func (s *Scope) Provide(constructor interface{}, opts ...ProvideOption) error {
return nil
}

func (s *Scope) provide(ctor interface{}, opts provideOptions) (err error) {
func (s *Scope) provide(ctor any, opts provideOptions) (err error) {
// If Export option is provided to the constructor, this should be injected to the
// root-level Scope (Container) to allow it to propagate to all other Scopes.
origScope := s
Expand Down
Loading