-
Notifications
You must be signed in to change notification settings - Fork 468
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
[Platform Compatibility Analyzer] Indicate why the current code violates the rule #4021
Comments
Maybe. I'm concerned that they might not understand what this means. |
The final messaging updated by @jeffhandley's suggestion
Now we are receiving feedbacks that [SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
public void SupportedOnWindowsAndLinuxOnly() { }
public void Caller()
{
SupportedOnWindowsAndLinuxOnly(); // warns: 'SupportedOnWindowsAndLinuxOnly' is supported on 'Windows'
// warns: 'SupportedOnWindowsAndLinuxOnly' is supported on 'Linux'
} Another examples of having two warnings: [UnsupportedOSPlatform("windows")]
[SupportedOSPlatform("10.0.19041.0")]
public void StartWindowsSupportFromCertainVersion() { }
public void Caller()
{
StartWindowsSupportFromCertainVersion();
// warns :'StartWindowsSupportFromCertainVersion' is unsupported on 'windows'
// warns :'StartWindowsSupportFromCertainVersion' is supported on 'windows' 10.0.1903 and later
}
[SupportedOSPlatform("windows")]
[UnsupportedOSPlatform("windows11.0")]
public void SupportedOnWindowsUnsupportedOnWindows11() { }
public void Caller2()
{
SupportedOnWindowsUnsupportedOnWindows11();
// warns :'SupportedOnWindowsUnsupportedOnWindows11' is supported on 'windows'
// warns :'SupportedOnWindowsUnsupportedOnWindows11' is unsupported on 'windows' 11 and later
}
[UnsupportedOSPlatform("windows")]
[SupportedOSPlatform("windows11.0")]
[UnsupportedOSPlatform("windows12.0")]
public void UnsupportedOnWindowsSupportedOnWindows11UnsupportedOnWindows12() { }
public void Caller3()
{
UnsupportedOnWindowsSupportedOnWindows11UnsupportedOnWindows12();
// warns :'UnsupportedOnWindowsSupportedOnWindows11UnsupportedOnWindows12' is supported on 'windows'
// warns :'UnsupportedOnWindowsSupportedOnWindows11UnsupportedOnWindows12' is unsupported on 'windows' 11 and later
} Which also not looks meaningful. Based on the feedbacks I propose the following messaging:
(*) Any other support could be warned with a separate message [SupportedOSPlatform("Windows")]
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("Linux")]
public void SupportedOnWindowsAndLinuxOnly() { }
public void Caller()
{
// warns: 'SupportedOnWindowsAndLinuxOnly' is only supported on 'Windows', `ios` and 'Linux'
SupportedOnWindowsAndLinuxOnly();
}
[UnsupportedOSPlatform("windows")]
[SupportedOSPlatform("10.0.19041.0")]
public void StartWindowsSupportFromCertainVersion() { }
public void Caller()
{
// warns :'StartWindowsSupportFromCertainVersion' is supported on 'windows' only from version 10.0.19041.0 and later
StartWindowsSupportFromCertainVersion();
}
[SupportedOSPlatform("windows")]
[UnsupportedOSPlatform("windows11.0")]
public void SupportedOnWindowsUnsupportedOnWindows11() { }
public void Caller2()
{
// warns :'SupportedOnWindowsUnsupportedOnWindows11' is unsupported on 'windows' from version 11 and later
SupportedOnWindowsUnsupportedOnWindows11();
}
[UnsupportedOSPlatform("windows")]
[SupportedOSPlatform("windows11.0")]
[UnsupportedOSPlatform("windows12.0")]
public void UnsupportedOnWindowsSupportedOnWindows11UnsupportedOnWindows12() { }
public void Caller3()
{
// warns :'UnsupportedOnWindowsSupportedOnWindows11UnsupportedOnWindows12' is supported on 'windows' from version 11.0 to 12.0
UnsupportedOnWindowsSupportedOnWindows11UnsupportedOnWindows12();
}
[SupportedOSPlatform("windows11.0")]
[UnsupportedOSPlatform("windows12.0")]
public void SupportedOnWindows11UnsupportedOnWindows12() { }
public void Caller4()
{
// warns :'SupportedOnWindows11UnsupportedOnWindows12' is only supported on 'windows' from version 11.0 to 12.0
SupportedOnWindows11UnsupportedOnWindows12();
} |
I like where this is going. I suggest a couple of tweaks. We changed "in 'windows'" to "on 'windows'" previously, which I've reflected here too.
Here are some notes:
|
@jeffhandley are you suggesting include the call site targets/attributes in the message? Could you write some examples of how the wording could be? |
Yep, copied from old messaging, thanks
Sounds good |
It feels weird not to have the versions also quoted: Besides, I think that having the list of what is currently recognized, as suggested on the first comment, would be helpful for debugging/understanding the problem. |
We cannot make
Are you referring to the suggestion in the original description about including the call site like below?
For me this messages not that clear, i think its need some improvement |
@gewarren do you have any suggestions for the below messages?
|
I'm coming up blank trying to think of a good way to communicate a scenario such as this:
We could ostensibly want to produce a message like this:
I presume we wouldn't want messages that long. But it's hard to express all of the data in a succinct and helpful way. |
That doesn't seem prohibitively long to me: |
So the example above will look like:
Sounds good to me 👍 For many os support/unsupport case platforms with or without a version looks a little odd, but i think it is fine: Plus there could be a multitargeted call site, in that case, it could be something like this:
How is it sound? |
That's looking good to me. Under what condition would we hit "but this call site is multitargeted"? Depending on that answer, I think we might want to pick a different word instead of "multitargeted." Instead of "this call site" do folks think "this code" would be OK? |
It means the call site has no any
For me, call site sounds more meaningful, but i am OK if we decide to go with "code" |
Thanks. Multi-targeting usually makes me think of having multiple target frameworks in the project file. https://devblogs.microsoft.com/dotnet/the-future-of-net-standard/ doesn't really define a term for @terrajobst @stephentoub do you have a suggestion for what word we should use to describe an API that is supported everywhere? I'm fine with "call site" too. |
"on all platforms"? |
Fixed with #4438 |
Analyzer
Diagnostic ID: CA1416 Platform Compatibility Analyzer
Describe the improvement
When a diagnostic is raised, the message includes information about the target method, such as:
But the diagnostic doesn't indicate what platform support was determined for the call site. We could guide users to resolve issues more easily by including in the message something indicating what support the current code has.
The text was updated successfully, but these errors were encountered: