neo-devpack-dotnet icon indicating copy to clipboard operation
neo-devpack-dotnet copied to clipboard

NCCS raises nullable context error even when Nullable enabled in csproj file

Open devhawk opened this issue 4 years ago • 6 comments

In C# proj file:

  <PropertyGroup>
    <NeoContractName>SafePurchase</NeoContractName>
    <NeoExpressBatchFile>..\express.batch</NeoExpressBatchFile>
    <Nullable>enable</Nullable>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

Command line:

> dotnet nccs --debug --no-optimize "C:\Users\harry\Source\neo\seattle\samples\safe-purchase\contract\safe-purchase.csproj" --contract-name SafePurchase
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Users\harry\Source\neo\seattle\samples\safe-purchase\contract\SafePurchaseContract.cs(73,122): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
C:\Users\harry\Source\neo\seattle\samples\safe-purchase\contract\SafePurchaseContract.cs(68,27): warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
Created C:\Users\harry\Source\neo\seattle\samples\safe-purchase\contract\bin\sc\SafePurchase.nef
Created C:\Users\harry\Source\neo\seattle\samples\safe-purchase\contract\bin\sc\SafePurchase.manifest.json
Created C:\Users\harry\Source\neo\seattle\samples\safe-purchase\contract\bin\sc\SafePurchase.nefdbgnfo
Compilation completed successfully.

The warning CS8632 lines should not be appearing

devhawk avatar Oct 15 '21 20:10 devhawk

@devhawk Please check #687

erikzhang avatar Oct 19 '21 06:10 erikzhang

@devhawk Please check #687

You've changed from defaulting Nullable options to Disabled to hardcoding Nullable options to Annotations. So if a project doesn't specify Nullable in their project file (which is the default as of .NET 5) then they will get a bunch of nullability warnings from NCCS than they likely won't understand and won't match the output of C# compiler.

devhawk avatar Oct 20 '21 18:10 devhawk

According to the docs in https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references

annotations: The compiler doesn't perform null analysis or emits warnings when code might dereference null.

It won't emit warnings. And the result of my test is the same.

erikzhang avatar Oct 21 '21 06:10 erikzhang

It won't emit warnings. And the result of my test is the same.

Now it won't ever emit warnings, even if the user has explicitly opted-in to getting the warnings.

devhawk avatar Nov 01 '21 20:11 devhawk

Further thoughts over on the PR : https://github.com/neo-project/neo-devpack-dotnet/pull/687#discussion_r740518411

devhawk avatar Nov 01 '21 20:11 devhawk

Now it won't ever emit warnings, even if the user has explicitly opted-in to getting the warnings.

The users will get the warnings in IDE.

erikzhang avatar Nov 02 '21 04:11 erikzhang