GenAPI can generate ambiguous call to base constructor
See original GitHub issueWhen GenAPI defines arguments to a base constructor, it uses default!
but this can lead to an ambiguous call when the base type has constructor overloads with the same number of parameters but different types.
An example of this is the generated code for NuGet.Protocol.6.5.0:
public partial class SourcePackageDependencyInfo : Packaging.Core.PackageDependencyInfo
{
public SourcePackageDependencyInfo(Packaging.Core.PackageIdentity identity, System.Collections.Generic.IEnumerable<Packaging.Core.PackageDependency> dependencies, bool listed, SourceRepository source, System.Uri downloadUri, string packageHash) : base(default!, default!) { }
This leads to the following compiler error:
error CS0121: The call is ambiguous between the following methods or properties: 'PackageDependencyInfo.PackageDependencyInfo(PackageIdentity, IEnumerable<PackageDependency>)' and 'PackageDependencyInfo.PackageDependencyInfo(string, NuGetVersion)
This can be solved by explicitly casting default
to the desired type:
: base((Packaging.Core.PackageIdentity)default!, (System.Collections.Generic.IEnumerable<Packaging.Core.PackageDependency>)default!) { }
Issue Analytics
- State:
- Created 5 months ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
GenAPI can generate ambiguous call to base constructor
When GenAPI defines arguments to a base constructor, it uses default! but this can lead to an ambiguous call when the base type...
Read more >Call to template base constructor is ambiguous
You can solve your problem by making the constructor call unambiguous: template<class T> struct Foo: public T, public Bar<T> { Foo(): ...
Read more >Why does the error message “Call to constructor of ' ' is ...
ambiguous means the compiler found multiple “valid” choices and refused to make the choice for you. You need to add clarifying information (usually...
Read more >Ambiguous call false positive error when using constructor ...
CPP-11804 Using-declaration to inherit ctors resolves object construction as ambiguous if derived and base class have ctors with same signature.
Read more >Ambiguous call error during compilation when explicit ...
In this case compiler takes both f() functions but it should notice, that first is not available and it should generate code with...
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 FreeTop 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
Top GitHub Comments
https://github.com/dotnet/sdk/blob/dabb52e63c2a171bdf519d2123470a260d6d1cb4/src/Tests/Microsoft.DotNet.GenAPI.Tests/CSharpFileBuilderTests.cs#L1466
Fix is in https://github.com/dotnet/roslyn/pull/67893. Once we can get a new build of roslyn with this fix in SDK we can resolve this (and re-enable the test).