Skip to content

Conversation

@RikkiGibson
Copy link
Member

Closes #44129


[Fact]
[WorkItem(44129, "https://github.com/dotnet/roslyn/issues/44129")]
public void DelegateCreation_FromMethodGroup_NullabilityAttributes()
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding some variations of this test taking into account variance. Delegate types with out parameters and these attributes, for example. For the same type of scenario, also consider testing usage of MaybeNullWhen.

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 did not test with 'out' parameters because it turns out they are not covariant in the language, but I added a test for by-value parameters and returns.

I do feel like the variance checks themselves are fairly well exercised by the overload resolution tests--delegates are just an analogous reuse of those checks, so it feels like it might be OK to not cover every last scenario

string? M1(string s)
{
var d = (D)M;
var d = (D)M1; // 1
Copy link
Member Author

Choose a reason for hiding this comment

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

To clarify why these tests changed: the nullable override analysis will refrain from warning about parameters if we have already warned about the return type. Thus to exercise all the same code paths in this test we need to have a method with an incompatible return type and another method with a compatible one.

}

CL0<string?> M1(CL0<string> x) { throw new System.Exception(); }
CL0<string> M2(CL0<string> x) { throw new System.Exception(); }
Copy link
Member Author

Choose a reason for hiding this comment

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

This test changed for the same reason as #46953 (comment).

@RikkiGibson RikkiGibson requested review from a team and 333fred August 24, 2020 18:32
@RikkiGibson
Copy link
Member Author

Please review @dotnet/roslyn-compiler

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 4)

@RikkiGibson RikkiGibson requested a review from a team August 25, 2020 00:19
@RikkiGibson
Copy link
Member Author

@dotnet/roslyn-compiler Please review

@jcouv jcouv self-assigned this Aug 26, 2020
@jcouv
Copy link
Member

jcouv commented Aug 26, 2020

Wouldn't have thought to re-use the override check logic, but it makes sense. Neat!

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 4)

@RikkiGibson RikkiGibson merged commit 14731c8 into dotnet:master Aug 26, 2020
@ghost ghost added this to the Next milestone Aug 26, 2020
@RikkiGibson RikkiGibson deleted the delegate-flow-annotations branch August 26, 2020 21:06
333fred added a commit to 333fred/roslyn that referenced this pull request Aug 27, 2020
…-only-errors

* upstream/master: (236 commits)
  Fix bug when "End statement" is used in single-line if (dotnet#47062)
  Solution asset cache refactoring (dotnet#46948)
  add specific tests to validate behavior between keys and snapshots
  Extract into separate files
  rename parameters
  rename parameters
  rename parameters
  rename parameters
  Add CancellationToken parameters to SyntaxTreeOptionsProvider
  Reuse nullable override checks for delegate conversions (dotnet#46953)
  Introduce warning for multiple entry points (sync + async) (dotnet#46832)
  Switch from throwing NotImplementedException and return E_NOTIMPL
  Delete Building for Core CLR.md (dotnet#47146)
  Adjust PrintMembers to avoid boxing and avoid extra space (dotnet#47095)
  Track asynchronous operation in InProcLanguageServer
  Use Task.FromCanceled where appropriate
  Apply suggestions from code review
  Address feedback
  Expose ParseOptions on generator context (dotnet#46919)
  Remove redundant statement in added tests
  ...
@allisonchou allisonchou removed this from the Next milestone Aug 31, 2020
@allisonchou allisonchou added this to the 16.8.P3 milestone Aug 31, 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.

Roslyn doesn't check nullability violations in delegate conversions caused by flow annotations

4 participants