consulo / consulo-csharp

Languages: C#
Apache License 2.0
50 stars 6 forks source link

C# 8.0 nullable types not supported #553

Closed mohitatray closed 4 years ago

mohitatray commented 4 years ago
string? text = "mohit"

Question mark should not be highlighted as syntax error as it specifies that variable is nullable string. Implement nullable types in C# 8.0.

VISTALL commented 4 years ago

Hello. I will suppress this check for 8+ version. Can you say .net version which you use? (unity maybe version), etc

Thanks

mohitatray commented 4 years ago

<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> Although the .net version doesn't matter, you can use C# 8.0 nullable types even in .net 2.0. C# version is totally independent of .net version. C# 8.0 is the C# compiler version whereas .net version is which framework the app depends on.

I am using Consulo for working on a Mono project (and added GTK sharp NuGet package to make GTK apps).

You also need to do null checks. For example let's say you have a method which takes in a string like this --

void Trim(string s) {
    // Some code
}

Now you are not allowed to call this method with null parameter like this -- Trim(null); // Passing null is not allowed because parameter is a non-null string type Because Trim method takes in a parameter which is a non-null string type, you cannot call Trim(null). It should atleast show a warning if not error.

This is only applicable for C# 8.0. Nothing is changed in C# versions before that. In C# 8.0, every reference type which doesn't have ? at the end is a non-null type. You cannot assign null to it.

VISTALL commented 4 years ago

Thanks - .NET version just for testing.

VISTALL commented 4 years ago

Hello. I added suppressing CS0453 for C# 8+ code for disable red code.

After my review i create new issue - https://github.com/consulo/consulo-csharp/issues/554.

Need some time for fix all those problems.

Thanks