Naming conflict with source generator
See original GitHub issueDescription
- Create unity project and add VContainer package
- Add VContainer.SourceGenerator
- Create script as following:
using VContainer;
public class Class1 {
readonly IObjectResolver _resolver;
public Class1(IObjectResolver resolver) => _resolver = resolver;
}
Expected Behaviour
All clean, everything is happy.
Current Behaviour
Generated Class1GeneratedInjector.g.cs
:
using System;
using System.Collections.Generic;
using VContainer;
class Class1GeneratedInjector : IInjector
{
public object CreateInstance(IObjectResolver resolver, IReadOnlyList<IInjectParameter> parameters)
{
var resolver = resolver.ResolveOrParameter(typeof(global::VContainer.IObjectResolver), "resolver", parameters);
var instance = new Class1((global::VContainer.IObjectResolver)resolver);
Inject(instance, resolver, parameters);
return instance;
}
public void Inject(object instance, IObjectResolver resolver, IReadOnlyList<IInjectParameter> parameters)
{
return;
}
}
Unity console shown as follows:
VContainer.SourceGenerator\VContainer.SourceGenerator.VContainerSourceGenerator\Class1GeneratedInjector.g.cs(9,14): error CS0136: A local or parameter named 'resolver' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
VContainer.SourceGenerator\VContainer.SourceGenerator.VContainerSourceGenerator\Class1GeneratedInjector.g.cs(9,25): error CS0841: Cannot use local variable 'resolver' before it is declared
VContainer.SourceGenerator\VContainer.SourceGenerator.VContainerSourceGenerator\Class1GeneratedInjector.g.cs(11,27): error CS1503: Argument 2: cannot convert from 'object' to 'VContainer.IObjectResolver'
Environment
- VContainer 1.13.0
- Unity 2021.3.16f1
- Windows 11 21H2
Issue Analytics
- State:
- Created 7 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Feedback from writing a source generator · Issue #44929
When generating types using S.R.E., we have the luxury of unspeakable names, ensuring that field/local names don't clash with field/local names ...
Read more >The code generator does not take into account naming ...
when run graphql-codegen to produce code, it has produced the same name type. Expected behavior. The code generator needs to take into account ......
Read more >Solving the source generator 'marker attribute' problem
In this post I describe how I solved a problem I've been wrestling with around source generators: where to put the 'marker attributes'...
Read more >Should a Source Generator be in its own assembly?
1. There is at least one reason - to isolate build time dependencies (so they are not included into the output). · Looks...
Read more >Question - Source Generator generates code multiple times
I was able to make my source generator work in Unity 2021.3, but there's one problem - it generates code multiple times -...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@chikacc @spikeliu1984 @th3d0g Sorry for the late response.
I’ve released a fix. https://github.com/hadashiA/VContainer/releases/tag/1.13.1 If you still have problems, please reopen.
VContainer.SourceGenerator\VContainer.SourceGenerator.VContainerSourceGenerator\MessagePipe.VContainer.ObjectResolverProxyGeneratedInjector.g.cs(11,18): error CS0136: A local or parameter named 'resolver' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter VContainer.SourceGenerator\VContainer.SourceGenerator.VContainerSourceGenerator\MessagePipe.VContainer.ObjectResolverProxyGeneratedInjector.g.cs(11,29): error CS0841: Cannot use local variable 'resolver' before it is declared VContainer.SourceGenerator\VContainer.SourceGenerator.VContainerSourceGenerator\MessagePipe.VContainer.ObjectResolverProxyGeneratedInjector.g.cs(13,31): error CS1503: Argument 2: cannot convert from 'object' to 'VContainer.IObjectResolver'
Not sure if it’s the same problem. I’m seeing the same error when MessagePipe is imported.Environment VContainer 1.13.0 Unity 2022.2.8f1