Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
6d1630d2
F
fsharp
项目概览
dotNET Platform
/
fsharp
10 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6d1630d2
编写于
6月 13, 2022
作者:
E
Edgar Gonzalez
提交者:
GitHub
6月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ObsoleteAttribute isn't taken into account when used on type (#13257)
上级
69c8950d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
248 addition
and
24 deletion
+248
-24
src/Compiler/Checking/AttributeChecking.fs
src/Compiler/Checking/AttributeChecking.fs
+25
-23
tests/FSharp.Compiler.ComponentTests/Language/AttributeCheckingTests.fs
...ompiler.ComponentTests/Language/AttributeCheckingTests.fs
+223
-1
未找到文件。
src/Compiler/Checking/AttributeChecking.fs
浏览文件 @
6d1630d2
...
@@ -391,27 +391,36 @@ let CheckILFieldAttributes g (finfo:ILFieldInfo) m =
...
@@ -391,27 +391,36 @@ 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
)
=
let
search
=
CheckEntityAttributes
g
minfo
.
ApparentEnclosingTyconRef
m
++
(
fun
()
->
BindMethInfoAttributes
m
minfo
let
search
=
(
fun
ilAttribs
->
Some
(
CheckILAttributes
g
false
ilAttribs
m
))
BindMethInfoAttributes
m
minfo
(
fun
fsAttribs
->
(
fun
ilAttribs
->
Some
(
CheckILAttributes
g
false
ilAttribs
m
))
let
res
=
(
fun
fsAttribs
->
CheckFSharpAttributes
g
fsAttribs
m
++
(
fun
()
->
let
res
=
if
Option
.
isNone
tyargsOpt
&&
HasFSharpAttribute
g
g
.
attrib_RequiresExplicitTypeArgumentsAttribute
fsAttribs
then
CheckFSharpAttributes
g
fsAttribs
m
++
(
fun
()
->
ErrorD
(
Error
(
FSComp
.
SR
.
tcFunctionRequiresExplicitTypeArguments
(
minfo
.
LogicalName
),
m
))
if
Option
.
isNone
tyargsOpt
&&
HasFSharpAttribute
g
g
.
attrib_RequiresExplicitTypeArgumentsAttribute
fsAttribs
then
else
ErrorD
(
Error
(
FSComp
.
SR
.
tcFunctionRequiresExplicitTypeArguments
(
minfo
.
LogicalName
),
m
))
CompleteD
)
else
Some
res
)
CompleteD
)
Some
res
)
#
if
!
NO_TYPEPROVIDERS
#
if
!
NO_TYPEPROVIDERS
(
fun
provAttribs
->
Some
(
CheckProvidedAttributes
g
m
provAttribs
))
(
fun
provAttribs
->
Some
(
CheckProvidedAttributes
g
m
provAttribs
))
#
else
#
else
(
fun
_
provAttribs
->
None
)
(
fun
_
provAttribs
->
None
)
#
endif
#
endif
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.
...
@@ -471,13 +480,6 @@ let PropInfoIsUnseen m pinfo =
...
@@ -471,13 +480,6 @@ let PropInfoIsUnseen m pinfo =
|
ProvidedProp
(_
amap
,
pi
,
m
)
->
|
ProvidedProp
(_
amap
,
pi
,
m
)
->
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
=
...
...
tests/FSharp.Compiler.ComponentTests/Language/AttributeCheckingTests.fs
浏览文件 @
6d1630d2
...
@@ -41,4 +41,226 @@ type C() =
...
@@ -41,4 +41,226 @@ type C() =
"""
"""
|>
ignoreWarnings
|>
ignoreWarnings
|>
compile
|>
compile
|>
shouldSucceed
|>
shouldSucceed
\ No newline at end of file
[<
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录