Skip to content

Compiler ignores obsolete attribute for enum cases. #6628

@dbarbashov

Description

@dbarbashov

When enum case marked with [<Obsolete>], compiler doesn't give warning.
Even with [<Obsolete("Hello, world!", true)>] it still compiles.

Repro steps

  1. Make enum

  2. Tag some case with [<Obsolete>] attribute

  3. Try use it somewhere

Example script:

open System

type MyDU =
    | Case1
    | [<Obsolete>] Case2
    
let xx = MyDU.Case2 // <- gives warning

type MyEnum =
    | Case3 = 0
    | [<Obsolete>] Case4 = 1
    
let yy = MyEnum.Case4 // <- no warning 

printfn "%A %A" xx yy 

Expected behavior

When enum case is marked as obsolete, compiler should give warning or error depending on Obsolete attribute configuration

Actual behavior

No compiler warning or error

Related information

OS: Ubuntu 16.04

$ dotnet --version
2.2.203

dotnet fsi output:


Microsoft (R) F# Interactive version 10.4.0 for F# 4.6
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> open System

type MyDU =
    | Case1
    | [<Obsolete>] Case2
    
let xx = MyDU.Case2

type MyEnum =
    | Case3 = 0
    | [<Obsolete("hello, world!", true)>] Case4 = 1
    
let yy = MyEnum.Case4

printfn "%A %A" xx yy ;;

  let xx = MyDU.Case2
  ---------^^^^^^^^^^

/home/lkmfwe/stdin(7,10): warning FS0044: This construct is deprecated

Case2 Case4
type MyDU =
  | Case1
  | Case2
val xx : MyDU = Case2
type MyEnum =
  | Case3 = 0
  | Case4 = 1
val yy : MyEnum = Case4
val it : unit = ()

Metadata

Metadata

Assignees

Labels

Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.good first issuehelp wanted

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions