Skip to content

Instantly share code, notes, and snippets.

@hafuu
Last active December 30, 2015 03:58
Show Gist options
  • Save hafuu/7772505 to your computer and use it in GitHub Desktop.
Save hafuu/7772505 to your computer and use it in GitHub Desktop.
F# 3.1 で ObsoleteAttribute を使うときの注意点? RecordとObsoleteAttributeは相性が悪いようだ。もしRecordをObsoleteにするなら、すべてのフィールドにObsoleteAttributeを付けたほうが良さそう。
module ObsoleteAttributeTest
open System
module Record =
[<Obsolete>]
type Foo = {
A: string
B: int
}
let a = { A = "a"; B = 3} // no warning, but it should be warning
let b: Foo = { A = "a"; B = 4} // warning
let c { A = a } = a // no warning, but it should be warning
type Bar = {
[<Obsolete>] C: string
D: int
}
let d = { C = "a"; D = 1 } // warning
let e { C = c } = c // warning
let f { D = d } = d // no warning
let g (x: Bar) = x // no warning
module Union =
[<Obsolete>]
type Foo =
| A
| B
let a = A // warning
let b = B // warning
let c (x: Foo) = x // warning
type Bar =
| [<Obsolete>] C
| D
let e = C // warning
let f = D // no warning
let g (x: Bar) = x // no warning
module Class =
[<Obsolete>]
type Foo(a: string, b: int) =
member val A = a with get, set
member val B = b with get, set
let a = Foo("", 3) // no warning, but it should be warning
let b: Foo = Foo("", 3) // warning
type Bar(c: string, d: int) =
[<Obsolete>]
member val C = c with get, set
member val D = d with get, set
let c = Bar("", 3).C // warning
let d = Bar("", 3).D // no warning
type Baz [<Obsolete>](e: string, f: int) =
[<Obsolete>]
new () = Baz("", 3)
new(f) = Baz("", f)
member val E = e with get, set
member val F = f with get, set
let e = Baz("", 3) // warning
let f = Baz() // warning
let g = Baz(4) // no warning
module Module =
[<AutoOpen>]
[<Obsolete>]
module A =
let a = 3
[<Obsolete>]
module B = ()
module ModulTest =
open Module // no warning, but it should be warning
open Module.B // warning
let c = a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment