Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
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
8 changes: 4 additions & 4 deletions internal/wire/testdata/Cleanup/want/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions internal/wire/testdata/CleanupNameCollision/foo/foo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2018 The Wire Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
)

func main() {
bar, cleanup := injectFooCleanup()
fmt.Println(*bar)
cleanup()
fmt.Println(*bar)
}

type Foo int
type FooCleanup int

func provideFoo() (*Foo, func()) {
foo := new(Foo)
*foo = 42
return foo, func() { *foo = 0 }
}

func provideFooCleanup(foo *Foo) (*FooCleanup, func()) {
fooCleanup := new(FooCleanup)
*fooCleanup = 77
return fooCleanup, func() {
if *foo == 0 {
panic("foo cleaned up before foo cleanup")
}
*fooCleanup = 0
}
}
27 changes: 27 additions & 0 deletions internal/wire/testdata/CleanupNameCollision/foo/wire.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2018 The Wire Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build wireinject
// +build wireinject

package main

import (
"github.com/google/wire"
)

func injectFooCleanup() (*FooCleanup, func()) {
wire.Build(provideFoo, provideFooCleanup)
return nil, nil
}
1 change: 1 addition & 0 deletions internal/wire/testdata/CleanupNameCollision/pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example.com/foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
77
0
18 changes: 18 additions & 0 deletions internal/wire/testdata/CleanupNameCollision/want/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions internal/wire/testdata/PartialCleanup/want/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/wire/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func (ig *injectorGen) funcProviderCall(lname string, c *call, injectSig outputS
ig.p("\t%s", lname)
prevCleanup := len(ig.cleanupNames)
if c.hasCleanup {
cname := disambiguate("cleanup", ig.nameInInjector)
cname := disambiguate(lname+"Cleanup", ig.nameInInjector)
ig.cleanupNames = append(ig.cleanupNames, cname)
ig.p(", %s", cname)
}
Expand Down