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

CLSCompliant(true) check for arrays as attribute arguments triggers on internal types #68526

Open
jkoritzinsky opened this issue Jun 9, 2023 · 9 comments · May be fixed by #68527
Open

CLSCompliant(true) check for arrays as attribute arguments triggers on internal types #68526

jkoritzinsky opened this issue Jun 9, 2023 · 9 comments · May be fixed by #68527
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug
Milestone

Comments

@jkoritzinsky
Copy link
Member

jkoritzinsky commented Jun 9, 2023

Version Used: .NET 8.0.100 P4 SDK

Steps to Reproduce:

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly:CLSCompliant(true)]

file class Foo
{
    [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvMemberFunction) })] // CS3016
    internal static void Bar(nint x){}
}

[CLSCompliant(false)] // CS3019
internal class Baz
{
    [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvMemberFunction) })] // CS3016 if CLSCompliant(false) is removed
    internal static void Bar(nint x){}
}

Warnings:

warning CS3019: CLS compliance checking will not be performed on 'Baz' because it is not visible from outside this assembly
warning CS3016: Arrays as attribute arguments is not CLS-compliant

If the CLSCompliant(false) attribute is removed, then a second CS3016 diagnostic is reported instead of CS3019.

SharpLab link

This is particularly rough for file-scoped types that can't be made partial.

Diagnostic Id: CS3016

Expected Behavior:

No CLS compliance warnings on array attribute parameters on attributes on non-exposed types.

Actual Behavior:

CLS compliance warnings on array attribute parameters on attributes on non-exposed types, and CS3019 if I put CLSCompliant(false) on the type with the attribute.

@RikkiGibson
Copy link
Contributor

I don't see any problem with making the change, especially for the file type scenario, but I wondered if IVT needs to be accounted for in the normal internal type scenario? Maybe it's already accounted for, or it's such an unusual case that it doesn't matter?

@jkoritzinsky
Copy link
Member Author

My PR that fixes this uses the same accessibilty check as the rest of the CLS Compliance checking (such as for method signatures), so it should behave identically with respect to IVT.

@AlekseyTs
Copy link
Contributor

@jkoritzinsky Please include complete repro in the description. Links to external resources are good, but they are not a replacement. What would we do if that external resource disappears? Also, please include complete wording of the problematic diagnostic, I am pretty sure very small number of people remember what CS3016 is about.

@jkoritzinsky
Copy link
Member Author

Updated the issue with the source and diagnostics inline in addition to the SharpLab link.

@AlekseyTs
Copy link
Contributor

@jkoritzinsky

Updated the issue with the source and diagnostics inline

Could you please clarify location for each of the warnings?

@jkoritzinsky
Copy link
Member Author

Updated

@AlekseyTs
Copy link
Contributor

I think triage should decide what path we should take here. It appears, that originally Roslyn had the attribute check suppressed based on accessibility of the target. Then, we explicitly changed that behavior back to accessibility independent behavior. Do we want to flip back again after that many years? Apparently we had a good enough reason to end up where we are today with respect to the check.

@jcouv jcouv added 4 - In Review A fix for the issue is submitted for review. Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 26, 2023
@jcouv jcouv added this to the Backlog milestone Jun 26, 2023
@elachlan
Copy link
Contributor

@AlekseyTs When did the behavior change? If it indeed was changed to the current behavior, it should probably be documented as by design and the suppression via the CLSCompliant(false) should then work (#68560)

@elachlan
Copy link
Contributor

Related: #4293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants