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

Tweak diagnostics to account for records #46341

Merged
merged 36 commits into from
Jul 31, 2020
Merged

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Jul 26, 2020

Fixes #45207

";
var comp = CreateCompilation(text);
comp.GetDeclarationDiagnostics().Verify(
// (2,8): error CS0146: Circular base class dependency involving 'B<A<T>>' and 'A<T>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class [](start = 54, length = 5)

Is this accurate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a better idea. I'm planning to leave this as-is.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jul 27, 2020

Done with review pass (iteration 29) #Closed

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signing off on the IDE side of things; the compiler side was not looked at.

record R : I, Base;
";
CreateCompilation(source).VerifyDiagnostics(
// (4,15): error CS1722: Base type 'Base' must come before any interfaces
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since "base type" includes interfaces, I'll revert to "base class" here as well.

@jcouv jcouv requested a review from AlekseyTs July 28, 2020 14:22
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (iteration 31)

@jcouv
Copy link
Member Author

jcouv commented Jul 28, 2020

@dotnet/roslyn-compiler for a second review. Thanks

@@ -742,13 +742,13 @@
<value>The type '{0}' has no constructors defined</value>
</data>
<data name="ERR_NoNewAbstract" xml:space="preserve">
<value>Cannot create an instance of the abstract class or interface '{0}'</value>
<value>Cannot create an instance of the abstract type '{0}'</value>
Copy link
Member

@cston cston Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider "abstract type or interface" instead. #Closed

@@ -2007,16 +2007,16 @@ If such a class is used as a base class and if the deriving class defines a dest
<value>Invalid constraint type. A type used as a constraint must be an interface, a non-sealed class or a type parameter.</value>
</data>
<data name="ERR_InstanceMemberInStaticClass" xml:space="preserve">
<value>'{0}': cannot declare instance members in a static class</value>
<value>'{0}': cannot declare instance members in a static type</value>
Copy link
Member

@cston cston Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support static record? If not, consider reverting this. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support static record, but unfortunately we display many cascading diagnostics in those cases, where the original message would be confusing. See StaticRecordWithConstructorAndDestructor for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support static record, but unfortunately we display many cascading diagnostics in those cases, where the original message would be confusing.

Could we report an error for static record? See #46450.


In reply to: 463333098 [](ancestors = 463333098)

</data>
<data name="ERR_StaticBaseClass" xml:space="preserve">
<value>'{1}': cannot derive from static class '{0}'</value>
<value>'{1}': cannot derive from static type '{0}'</value>
Copy link
Member

@cston cston Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert if static record is not supported. #Closed

</data>
<data name="ERR_ConstructorInStaticClass" xml:space="preserve">
<value>Static classes cannot have instance constructors</value>
<value>Static types cannot have instance constructors</value>
Copy link
Member

@cston cston Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert if static record is not supported. #Closed

</data>
<data name="ERR_DestructorInStaticClass" xml:space="preserve">
<value>Static classes cannot contain destructors</value>
<value>Static types cannot contain destructors</value>
Copy link
Member

@cston cston Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert if static record is not supported. #Closed

");

c.VerifyDiagnostics(
// (8,12): error CS0060: Inconsistent accessibility: base type 'X<B.C.D.E>' is less accessible than class 'B.C'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   // [](start = 12, length = 10)

Indenting looks off.

";
var comp = CreateCompilation(text);
comp.GetDeclarationDiagnostics().Verify(
// (2,8): error CS0146: Circular base class dependency involving 'B<A<T>>' and 'A<T>'
Copy link
Member

@cston cston Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circular base class [](start = 40, length = 19)

"Circular base type" here and below. #Closed

Copy link
Member Author

@jcouv jcouv Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for using "base class" is that the spec uses "base type" to encompass the base class and all interfaces.
See https://github.com/dotnet/csharplang/blob/master/spec/classes.md#type-parameter-constraints

So "base type" is incorrect (although intuitive). I'm leaving as-is for now unless we have a better name. #Closed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for using "base class" is that the spec uses "base type" to encompass the base class and all interfaces.

That sounds fine to me, but the resource string is currently "Circular base type dependency involving '{0}' and '{1}'"


In reply to: 463328299 [](ancestors = 463328299)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, got confused. The meaning of "base type" that I referenced is in the context of type constraints.

@jcouv jcouv merged commit e3c3fa3 into dotnet:master Jul 31, 2020
@ghost ghost modified the milestones: 16.8, Next Jul 31, 2020
@jcouv jcouv deleted the tweak-diagnostics branch July 31, 2020 15:49
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 31, 2020
* upstream/master: (304 commits)
  Tweak diagnostics to account for records (dotnet#46341)
  Diagnose precedence inversion in a warning wave (dotnet#46239)
  Remove PROTOTYPE tag (dotnet#45965)
  Only run a single pass of NullableWalker per-member (dotnet#46402)
  Fix crash, and offer "declare as nullable" for tuple fields (dotnet#46437)
  Simplify contract for RunWithShutdownBlockAsync
  Fix optprof plugin input
  check if EditorAdaptersFactoryService gives us a null buffer
  Cannot assign maybe-null value to TNotNull variable (dotnet#41445)
  Fix overload resolution to handle binary compat in the face of covariant returns (dotnet#46367)
  Same failure on Linux
  Skip some tests on Mac
  Added search option for inline parameter name hints
  Spelling
  tweak docs
  Improve comment
  Improve the "not exhaustive" diagnostic in the presence of a when clause. (dotnet#46143)
  PR feedback
  Use record keyword to display records (dotnet#46338)
  remove test that aserts .NET Standard should be prefered over .NET Framework
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 16.8.P2 Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need to review existing diagnostics in light of records
5 participants