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

Remove CS1701 and CS1702 warnings #66313

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Youssef1313
Copy link
Member

Very quick PR to fix #19640

@Youssef1313 Youssef1313 requested a review from a team as a code owner January 8, 2023 13:57
@ghost ghost added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jan 8, 2023
@Youssef1313 Youssef1313 marked this pull request as draft January 8, 2023 14:24
@Youssef1313
Copy link
Member Author

Draft for now. I'll debug the failing tests later :(
I'm okay in case someone wanted to complete this before me.

@AlekseyTs
Copy link
Contributor

Are all use-site diagnostics on symbols errors now? As in VB. If so, we probably should rename all relevant APIs that use "UseSiteDiagnostic" to "UseSiteError" to reflect the fact. Some checks for use-site errors (vs. warnings), if any, could be simplified as well. Also, we should see if calculation/merging of use-site diagnostics could be optimized/simplified (get out early, etc.) now.

@Youssef1313
Copy link
Member Author

Youssef1313 commented Jan 17, 2023

@AlekseyTs Could this be done in a separate follow-up PR (and open an issue to track that)?

@Youssef1313 Youssef1313 marked this pull request as ready for review January 17, 2023 20:19
@jcouv jcouv requested a review from AlekseyTs February 3, 2023 00:53
@AlekseyTs
Copy link
Contributor

AlekseyTs commented Feb 3, 2023

Could this be done in a separate follow-up PR (and open an issue to track that)?

I think that if we want to address the issue, we should do that without any need for an additional follow up. I do not see any urgency in stopping reporting the warnings. If we think that the issue is worth addressing, we should do that in its entirety.

@Youssef1313
Copy link
Member Author

@AlekseyTs I took a look

nullabilityDiagnosticsBuilderOpt.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.WRN_NullabilityMismatchInTypeParameterNotNullConstraint, containingSymbol.ConstructedFrom(), typeParameter, typeArgument))));
}
if (typeParameter.HasReferenceTypeConstraint &&
typeParameter.ReferenceTypeConstraintIsNullable == false &&
typeArgument.GetValueNullableAnnotation().IsAnnotated())
{
nullabilityDiagnosticsBuilderOpt.Add(new TypeParameterDiagnosticInfo(typeParameter, new UseSiteInfo<AssemblySymbol>(new CSDiagnosticInfo(ErrorCode.WRN_NullabilityMismatchInTypeParameterReferenceTypeConstraint, containingSymbol.ConstructedFrom(), typeParameter, typeArgument))));

and if I understand correctly, we can't get simplify anything here. Am I correct?

@AlekseyTs
Copy link
Contributor

and if I understand correctly, we can't get simplify anything here. Am I correct?

Are all use-site diagnostics on symbols errors now? As in VB.

I am primarily referring to the following APIs on Symbol:

        /// <summary>
        /// True if the symbol has a use-site diagnostic with error severity.
        /// </summary>
        internal bool HasUseSiteError
        {
            get
            {
                var info = GetUseSiteInfo();
                return info.DiagnosticInfo?.Severity == DiagnosticSeverity.Error;
            }
        }

        /// <summary>
        /// Returns diagnostic info that should be reported at the use site of the symbol, or default if there is none.
        /// </summary>
        internal virtual UseSiteInfo<AssemblySymbol> GetUseSiteInfo()
        {
            return default;
        }

By contrast VB has only:

        ''' <summary>
        ''' Returns dependencies and an error info for an error, if any, that should be reported at the use site of the symbol.
        ''' </summary>
        Friend Overridable Function GetUseSiteInfo() As UseSiteInfo(Of AssemblySymbol)
            Return Nothing
        End Function

If so, we probably should rename all relevant APIs that use "UseSiteDiagnostic" to "UseSiteError" to reflect the fact.

I was referring to legacy names for the APIs. So, I withdraw this suggestion.

Some checks for use-site errors (vs. warnings), if any, could be simplified as well.

Given the example where nullable warnings are added to the UseSiteInfo, we cannot make a general assumption that UseSiteInfo doesn't contain a warning. But it might be a valid assumption when we get it from symbol.

Also, we should see if calculation/merging of use-site diagnostics could be optimized/simplified (get out early, etc.) now.

I am primarily referring to the way we calculate value returned by Symbol.GetUseSiteInfo API. It is quite possible that there is nothing to optimize there, but it is worth checking, I think.

@@ -72,30 +72,11 @@ public void VersionUnification_SymbolUsed()
// reference asks for a higher version than available:
var testRefV2 = CreateCompilation("public class E : D { }", new MetadataReference[] { new CSharpCompilationReference(refV2), v1 }, assemblyName: "testRefV2");

// TODO (tomat): we should display paths rather than names "refV1" and "C"

testRefV1.VerifyDiagnostics(
Copy link
Contributor

Choose a reason for hiding this comment

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

VerifyDiagnostics

It doesn't feel like simply removing the verification of diagnostics is appropriate. I think at least we should verify that there is no diagnostics.

@@ -187,15 +168,7 @@ public void F()
new CSharpCompilationReference(refLibV2)
});

// TODO (tomat): we should display paths rather than names "RefLibV2" and "Lib"

main13.VerifyDiagnostics(
Copy link
Contributor

Choose a reason for hiding this comment

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

VerifyDiagnostics

According to the comment above, it looks like the goal of the test was to verify that: "higher version should be preferred over lower version regardless of the order of the references". It also looks like the fact was verified indirectly by checking diagnostics. If we no longer can rely on this approach, we should find a different way to verify the outcome. It feels like we might want other tests that primarily were verifying presence of the warnings (at least all tests in this file) be adjusted in a similar way.

@jcouv
Copy link
Member

jcouv commented May 10, 2023

Marking PR as draft for now, to make room in our review queue. Please undraft when ready for another look. Thanks

@jcouv jcouv marked this pull request as draft May 10, 2023 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warnings CS1701 and CS1702 should be removed
3 participants