Obsolete warning isn't produced for some obsolete symbol usages
[Obsolete("Class is obsolete")]
public class ObsoleteClass
{
}
let c1: ObsoleteClass = null
let c2 = ObsoleteClass()
Two warnings are expected, but only one is produced:

C# compiler produces two warnings:
ObsoleteClass c = new ObsoleteClass();
Is it on the main, or latest stable? I remember @edgarfgp was doing some changes there?
It's in 6.0.301 and in FCS from ~March.
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 _ -> ())
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:
@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 ?
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
@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
@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 I believe so 🙂