fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Obsolete warning isn't produced for some obsolete symbol usages

Open auduchinok opened this issue 3 years ago • 6 comments

[Obsolete("Class is obsolete")]
public class ObsoleteClass
{
}
let c1: ObsoleteClass = null
let c2 = ObsoleteClass()

Two warnings are expected, but only one is produced: Screenshot 2022-07-14 at 13 24 24

C# compiler produces two warnings:

ObsoleteClass c = new ObsoleteClass();
Screenshot 2022-07-14 at 13 27 20

auduchinok avatar Jul 14 '22 11:07 auduchinok

Is it on the main, or latest stable? I remember @edgarfgp was doing some changes there?

vzarytovskii avatar Jul 14 '22 11:07 vzarytovskii

It's in 6.0.301 and in FCS from ~March.

auduchinok avatar Jul 14 '22 11:07 auduchinok

There's the same behaviour for structs and delegates:

[Obsolete("Struct is obsolete")]
public struct ObsoleteStruct
{
}

[Obsolete("Interface is obsolete")]
public interface IObsoleteInterface
{
    int P { get; }
}

[Obsolete("Delegate is obsolete")]
public delegate void ObsoleteDelegate();
let s1: ObsoleteStruct = ObsoleteStruct()
let s2 = ObsoleteStruct()

let i1: IObsoleteInterface = null
let i2 = { new IObsoleteInterface with
             member this.P = 1 }

let d1: ObsoleteDelegate = null
let d2 = ObsoleteDelegate(fun _ -> ())
Screenshot 2022-07-14 at 13 43 28

auduchinok avatar Jul 14 '22 11:07 auduchinok

public class Class
{
    [Obsolete("Field is obsolete")] public static readonly int ObsoleteField = 1;

    [Obsolete("Method is obsolete")]
    public static void ObsoleteMethod()
    {
    }

    [Obsolete("Property is obsolete")] public static int ObsoleteProperty => 1;

    [Obsolete("Event is obsolete")] public static event EventHandler ObsoleteEvent;
}
Class.ObsoleteField |> ignore
Class.ObsoleteMethod()
Class.ObsoleteProperty |> ignore
Class.ObsoleteEvent |> ignore

No warning is produced for the event:

Screenshot 2022-07-14 at 14 15 44

auduchinok avatar Jul 14 '22 12:07 auduchinok

@vzarytovskii @auduchinok

Is it on the main, or latest stable? I remember @edgarfgp was doing some changes there?

I think is in main

It's in 6.0.301 and in FCS from ~March.

My changes where June 13 https://github.com/dotnet/fsharp/pull/13257 (See the testing scenarios to see this is fixed) And it did address some of the inconsistencies . But there are still some pending like https://github.com/dotnet/fsharp/issues/6628 and https://github.com/dotnet/fsharp/issues/11529

let c1: ObsoleteClass = null
let c2 = ObsoleteClass()

Try adding new before the class name ?

let c2 = new ObsoleteClass()

I think we can add more testing to validate this behaviours and see what is still missing ?

edgarfgp avatar Jul 14 '22 13:07 edgarfgp

I installed VS preview and I'm getting warning and errors where they are expected I believe . Except for

 [Obsolete("Event is obsolete")] public static event EventHandler ObsoleteEvent;
  Class.ObsoleteEvent |> ignore

So I think that might be a case that still missing

edgarfgp avatar Jul 15 '22 16:07 edgarfgp

@auduchinok I believe I have covered all the cases in this issue including events 😀See https://github.com/dotnet/fsharp/blob/main/tests/FSharp.Compiler.ComponentTests/Language/ObsoleteAttributeCheckingTests.fs

edgarfgp avatar Oct 11 '22 14:10 edgarfgp

@auduchinok I believe I have covered all the cases in this issue including events 😀See https://github.com/dotnet/fsharp/blob/main/tests/FSharp.Compiler.ComponentTests/Language/ObsoleteAttributeCheckingTests.fs

Good job Edgar!

Can this issue now be closed ?

T-Gro avatar Nov 14 '22 18:11 T-Gro

@T-Gro I believe so 🙂

edgarfgp avatar Nov 14 '22 18:11 edgarfgp