未验证 提交 6d1630d2 编写于 作者: E Edgar Gonzalez 提交者: GitHub

ObsoleteAttribute isn't taken into account when used on type (#13257)

上级 69c8950d
...@@ -391,8 +391,16 @@ let CheckILFieldAttributes g (finfo:ILFieldInfo) m = ...@@ -391,8 +391,16 @@ let CheckILFieldAttributes g (finfo:ILFieldInfo) m =
CheckProvidedAttributes amap.g m (fi.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) |> CommitOperationResult CheckProvidedAttributes amap.g m (fi.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) |> CommitOperationResult
#endif #endif
/// Check the attributes on an entity, returning errors and warnings as data.
let CheckEntityAttributes g (x:TyconRef) m =
if x.IsILTycon then
CheckILAttributes g (isByrefLikeTyconRef g m x) x.ILTyconRawMetadata.CustomAttrs m
else
CheckFSharpAttributes g x.Attribs m
/// Check the attributes associated with a method, returning warnings and errors as data. /// Check the attributes associated with a method, returning warnings and errors as data.
let CheckMethInfoAttributes g m tyargsOpt minfo = let CheckMethInfoAttributes g m tyargsOpt (minfo: MethInfo) =
CheckEntityAttributes g minfo.ApparentEnclosingTyconRef m ++ (fun () ->
let search = let search =
BindMethInfoAttributes m minfo BindMethInfoAttributes m minfo
(fun ilAttribs -> Some(CheckILAttributes g false ilAttribs m)) (fun ilAttribs -> Some(CheckILAttributes g false ilAttribs m))
...@@ -412,6 +420,7 @@ let CheckMethInfoAttributes g m tyargsOpt minfo = ...@@ -412,6 +420,7 @@ let CheckMethInfoAttributes g m tyargsOpt minfo =
match search with match search with
| Some res -> res | Some res -> res
| None -> CompleteD // no attribute = no errors | None -> CompleteD // no attribute = no errors
)
/// Indicate if a method has 'Obsolete', 'CompilerMessageAttribute' or 'TypeProviderEditorHideMethodsAttribute'. /// Indicate if a method has 'Obsolete', 'CompilerMessageAttribute' or 'TypeProviderEditorHideMethodsAttribute'.
/// Used to suppress the item in intellisense. /// Used to suppress the item in intellisense.
...@@ -472,13 +481,6 @@ let PropInfoIsUnseen m pinfo = ...@@ -472,13 +481,6 @@ let PropInfoIsUnseen m pinfo =
CheckProvidedAttributesForUnseen (pi.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) m CheckProvidedAttributesForUnseen (pi.PApply((fun st -> (st :> IProvidedCustomAttributeProvider)), m)) m
#endif #endif
/// Check the attributes on an entity, returning errors and warnings as data.
let CheckEntityAttributes g (x:TyconRef) m =
if x.IsILTycon then
CheckILAttributes g (isByrefLikeTyconRef g m x) x.ILTyconRawMetadata.CustomAttrs m
else
CheckFSharpAttributes g x.Attribs m
/// Check the attributes on a union case, returning errors and warnings as data. /// Check the attributes on a union case, returning errors and warnings as data.
let CheckUnionCaseAttributes g (x:UnionCaseRef) m = let CheckUnionCaseAttributes g (x:UnionCaseRef) m =
CheckEntityAttributes g x.TyconRef m ++ (fun () -> CheckEntityAttributes g x.TyconRef m ++ (fun () ->
......
...@@ -42,3 +42,225 @@ type C() = ...@@ -42,3 +42,225 @@ type C() =
|> ignoreWarnings |> ignoreWarnings
|> compile |> compile
|> shouldSucceed |> shouldSucceed
[<Fact>]
let ``Obsolete attribute is not taken into account when used on on a member and and instantiate the type`` () =
Fsx """
open System
type C() =
[<Obsolete("Use B instead", true)>]
member _.Update() = ()
let c = C()
"""
|> ignoreWarnings
|> compile
|> shouldSucceed
[<Fact>]
let ``Obsolete attribute is taken into account when used on type and and instantiate the type`` () =
Fsx """
open System
[<Obsolete("Use B instead", true)>]
type C() =
member _.Update() = ()
let c = C()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
[<Fact>]
let ``Obsolete attribute is taken into account when used on a member and invoking the member`` () =
Fsx """
open System
type C() =
[<Obsolete("Use B instead", true)>]
member _.Update() = ()
let c = C()
c.Update()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
[<Fact>]
let ``Obsolete attribute is taken into account when used on type and invoking the member`` () =
Fsx """
open System
[<Obsolete("Use B instead", true)>]
type C() =
member _.Update() = ()
let c = C()
c.Update()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCodes [ 101; 101]
|> withErrorMessages [ "This construct is deprecated. Use B instead"; "This construct is deprecated. Use B instead"]
[<Fact>]
let ``Obsolete attribute is taken into account when used on struct type and invoking the member`` () =
Fsx """
open System
[<Obsolete("Use B instead", true)>]
[<Struct>]
type C =
member _.Update() = ()
let c = C()
c.Update()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCodes [ 101; 101]
|> withErrorMessages [ "This construct is deprecated. Use B instead"; "This construct is deprecated. Use B instead"]
[<Fact>]
let ``Obsolete attribute is taken into account when used on struct type and instantiate the type`` () =
Fsx """
open System
[<Obsolete("Use B instead", true)>]
[<Struct>]
type C =
member _.Update() = ()
let c = C()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
[<Fact>]
let ``Obsolete attribute is taken into account when used on a struct member and invoking the member`` () =
Fsx """
open System
[<Struct>]
type C =
[<Obsolete("Use B instead", true)>]
member _.Update() = ()
let c = C()
c.Update()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
[<Fact>]
let ``Obsolete attribute is taken into account when used on a record property`` () =
Fsx """
open System
type C =
{ [<Obsolete("Use B instead", true)>] X: int }
let c = { X = 0 }
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
[<Fact>]
let ``Obsolete attribute is taken into account when used on a record and member invocation`` () =
Fsx """
open System
[<Obsolete("Use B instead", true)>]
type C =
{ X : int }
static member Update() = ()
C.Update()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
[<Fact>]
let ``Obsolete attribute is taken into account when used on a record member and method invocation`` () =
Fsx """
open System
type C =
{ X : int }
[<Obsolete("Use B instead", true)>]
static member Update() = ()
C.Update()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
[<Fact>]
let ``Obsolete attribute is taken into account when used on an enum and invocation`` () =
Fsx """
open System
[<Obsolete("Use B instead", true)>]
type Color =
| Red = 0
| Green = 1
let c = Color.Red
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
[<Fact>]
let ``Obsolete attribute is taken into account when used on an enum entry and invocation`` () =
Fsx """
open System
type Color =
| [<Obsolete("Use B instead", true)>] Red = 0
| Green = 1
let c = Color.Red
"""
|> ignoreWarnings
|> compile
|> shouldSucceed
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册