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

Poor diagnostic wrong number of Type Arguments... #34620

Open
YairHalberstadt opened this issue Mar 31, 2019 · 2 comments
Open

Poor diagnostic wrong number of Type Arguments... #34620

YairHalberstadt opened this issue Mar 31, 2019 · 2 comments
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings.
Milestone

Comments

@YairHalberstadt
Copy link
Contributor

YairHalberstadt commented Mar 31, 2019

... with a type that exists in both a generic and non generic version

Version Used:

master

Steps to Reproduce:

Compile the following code

using System;
public class C : IComparable<int, int> {}

https://sharplab.io/#v2:EYLgtghgzgLgpgJwD4AEAMACFBGA3AWACgUBmLAJgwGEMQMBJKgezAAcIEJgAbOAHgCWAOxgAaDMJgA+DAG8AvkA

Expected Behavior:

error CS0305: Using the generic type 'IComparable<T>' requires 1 type arguments

Actual Behavior:

error CS0308: The non-generic type 'IComparable' cannot be used with type arguments

Whilst the semantics are debatable, this error message is (almost) just plain false :-)

@gafter
Copy link
Member

gafter commented Mar 31, 2019

The diagnostic is precisely correct. See https://docs.microsoft.com/en-us/dotnet/api/system.icomparable?view=netframework-4.7.2 : the non-generic type IComparable indeed cannot be used with type arguments.

@gafter gafter added Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. labels Mar 31, 2019
@sharwell
Copy link
Member

sharwell commented Mar 31, 2019

I agree with @YairHalberstadt here (CS0305 is more likely related to the user's intent than CS0308). A similar situation occurs with ValueTuple<int, int, int, int, int, int, int, int, int>. Rather than assume the user meant to reference ValueTuple, it seems like the generic type with the closest number of type parameters should be used as the reference. For the original case above, this would be IComparable<T>. For the case I added, it would be ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>.

@gafter gafter added this to the Backlog milestone Jul 16, 2019
@gafter gafter added the Bug label Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings.
Projects
None yet
Development

No branches or pull requests

3 participants