Skip to content

Add new feature to fix invalid constraints.#59889

Merged
CyrusNajmabadi merged 4 commits intodotnet:release/dev17.3from
CyrusNajmabadi:fixConstraints
Mar 7, 2022
Merged

Add new feature to fix invalid constraints.#59889
CyrusNajmabadi merged 4 commits intodotnet:release/dev17.3from
CyrusNajmabadi:fixConstraints

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Mar 2, 2022

Followup to recent compiler work to detect this mistake and report a custom diagnostic for it.

Looks like this:

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner March 2, 2022 19:59
@ghost ghost added the Area-IDE label Mar 2, 2022
@CyrusNajmabadi CyrusNajmabadi changed the base branch from main to release/dev17.3 March 2, 2022 20:13
@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners March 2, 2022 20:13
@jcouv
Copy link
Copy Markdown
Member

jcouv commented Mar 3, 2022

I'm surprised this is targeting a specific release branch. Why not target main branch as usual?

docs/ide @dotnet/roslyn-ide

# Notify docs team for new breaking change documentation
docs/compilers/CSharp @dotnet/docs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should not be in this PR. It will be removed from main anyways. Likely related to PR targeting release/dev17.3 instead of main.

enumOrDelegateKeyword = default;
constraint = diagnostic.Location.FindNode(cancellationToken) as TypeConstraintSyntax;
if (constraint == null)
return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just to confirm, most of the cases returning false seem unreachable. This is just being defensive, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct. Compiler diagnostics come with no contracts/guarantees. They can and do change over time. So consumption code needs to be written to be resilient to that.

Debug.Assert(result || (_getTypeCache.TryGetValue(fullyQualifiedMetadataName, out var addedType) && ReferenceEquals(addedType, val)));
Debug.Assert(result
|| !_getTypeCache.TryGetValue(fullyQualifiedMetadataName, out var addedType) // Could fail if the type was already evicted from the cache
|| ReferenceEquals(addedType, val));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto, this change doesn't belong here

{
}",

}.RunAsync();
Copy link
Copy Markdown
Member

@jcouv jcouv Mar 3, 2022

Choose a reason for hiding this comment

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

nit: Blank line above RunAsync. Also in test above

await new VerifyCS.Test
{
TestCode = @"
class C<T> where T : {|CS9010:enum|}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see we only have tests for single constraint. I think that makes sense because no other constraint would be legal. However, consider testing with some other constraints for completeness.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure. happy to add.

}

[WpfFact]
public void TestReturnInSixQuotesMoreQuotesLaterOn()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure whether this is meant to be in this PR, or an artifact of targeting 17.3 branch.

var startDelimeterLength = 0;
var endDelimeterLength = 0;
for (int i = token.SpanStart, n = token.Span.End; i < n; position++)
for (int i = token.SpanStart, n = token.Span.End; i < n; i++)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Copy Markdown
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.

Done with review pass (iteration 10)

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

I'm surprised this is targeting a specific release branch. Why not target main branch as usual?

@jcouv I agree. But new features are not allowed in main currently. They have to go into 17.3

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

The other stuff got pulled in with retargetting. Once main is merged in, they'll go away

Copy link
Copy Markdown
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, but I'll wait until the extra changes no longer appear in diff to sign-off. Thanks

@CyrusNajmabadi CyrusNajmabadi requested a review from jcouv March 6, 2022 18:57
@CyrusNajmabadi CyrusNajmabadi merged commit 0a1831e into dotnet:release/dev17.3 Mar 7, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the fixConstraints branch March 7, 2022 02:34
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.

4 participants