Skip to content

Instantly share code, notes, and snippets.

@haacked
Last active March 23, 2021 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haacked/fcd8c18bef2e257d2c4a2dd31b9784cb to your computer and use it in GitHub Desktop.
Save haacked/fcd8c18bef2e257d2c4a2dd31b9784cb to your computer and use it in GitHub Desktop.
Weird roslyn waring
public interface IArgument
{
/// <summary>
/// The value of the argument sans quotes.
/// </summary>
string Value { get; }
}
public interface IArguments : IReadOnlyList<IArgument>, IArgument
{
void Deconstruct(out IArgument first, out IArgument second, out IArgument third);
}
var (verb, mention, description) = messageContext.Arguments; // messageContext.Arguments implements IArguments
// Error CA1508 : 'mention.Value is "not"' is always 'false'. Remove or refactor the condition(s) to avoid dead code.
if (verb.Value is "is" && mention.Value is "not")
{
}
// However, this works fine:
if (verb is {Value: "is"} && mention is {Value: "not" })
{
}
@haacked
Copy link
Author

haacked commented Mar 23, 2021

I have these set in the .csproj

<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>

...
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment