Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render bug in Scope Tree for duplicate provided values in child scopes #85

Open
polds opened this issue Aug 21, 2024 · 0 comments
Open

Comments

@polds
Copy link

polds commented Aug 21, 2024

I believe I have encountered a bug in rendering the Scope Tree when a child scope provides a value that was declared in the root/parent scope. The behavior is that when the Scope Tree is rendered it shows the duplicated value twice.

You can see what I mean with this repro:

package main

import (
	"context"
	"fmt"

	"github.com/samber/do/v2"
)

func main() {
	rootCtx := context.Background()

	// Create the rootScope with a context and a string provided.
	rootScope := do.New(
		do.Eager(rootCtx),
		do.Eager("Hello, World!"),
	)
	_ = do.MustInvoke[context.Context](rootScope) // Add (rootScope).context.Context to the invoked list.
	rootDebug := do.ExplainInjector(rootScope)
	fmt.Println(rootDebug.String())

	// Create a childScope with only a context.
	childScope := rootScope.Scope("child1",
		do.Eager(rootCtx),
	)
	_ = do.MustInvoke[context.Context](childScope) // Add (childScope).context.Context to the invoked list.
	childDebug := do.ExplainInjector(childScope)
	fmt.Println(childDebug.String())

	// Print provided and invoked services.
	for _, svc := range childScope.ListProvidedServices() {
		fmt.Printf("[Provided]: Scope: %s\t Scope ID: %s\tService: %s\n", svc.ScopeName, svc.ScopeID, svc.Service)
	}
	invokedServices := childScope.ListInvokedServices()
	for _, svc := range invokedServices {
		fmt.Printf("[Invoked] Scope: %s\t Scope ID: %s\tService: %s\n", svc.ScopeName, svc.ScopeID, svc.Service)
	}
}

Playground link

Result:

image

Expectation:

Like with listing the provided and invoked services I would expect that printing the Scope Tree would have only shown context.Context as being provided once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant