Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
53b2957f
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
53b2957f
编写于
7月 27, 2020
作者:
R
Rikki Gibson
提交者:
GitHub
7月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update argument state when parameter has not-null type (#46072)
上级
e128267a
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
1026 addition
and
584 deletion
+1026
-584
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
+9
-3
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
...rp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+995
-559
src/Compilers/CSharp/Test/Symbol/Symbols/Source/NullablePublicAPITests.cs
...harp/Test/Symbol/Symbols/Source/NullablePublicAPITests.cs
+22
-22
未找到文件。
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
浏览文件 @
53b2957f
...
...
@@ -4955,7 +4955,7 @@ static bool hasNoNonNullableCounterpart(TypeSymbol type)
case
RefKind
.
In
:
{
// learn from post-conditions [Maybe/NotNull, Maybe/NotNullWhen] without using an assignment
learnFromPostConditions
(
argument
,
parameterAnnotations
);
learnFromPostConditions
(
argument
,
parameter
Type
,
parameter
Annotations
);
}
break
;
case
RefKind
.
Ref
:
...
...
@@ -5139,11 +5139,15 @@ static TypeWithState applyPostConditionsWhenFalse(TypeWithState typeWithState, F
return
typeWithState
;
}
void
learnFromPostConditions
(
BoundExpression
argument
,
FlowAnalysisAnnotations
parameterAnnotations
)
void
learnFromPostConditions
(
BoundExpression
argument
,
TypeWithAnnotations
parameterType
,
FlowAnalysisAnnotations
parameterAnnotations
)
{
// Note: NotNull = NotNullWhen(true) + NotNullWhen(false)
bool
notNullWhenTrue
=
(
parameterAnnotations
&
FlowAnalysisAnnotations
.
NotNullWhenTrue
)
!=
0
;
bool
notNullWhenFalse
=
(
parameterAnnotations
&
FlowAnalysisAnnotations
.
NotNullWhenFalse
)
!=
0
;
bool
disallowNull
=
(
parameterAnnotations
&
FlowAnalysisAnnotations
.
DisallowNull
)
!=
0
;
bool
setNotNullFromParameterType
=
!
argument
.
IsSuppressed
&&
!
parameterType
.
Type
.
IsPossiblyNullableReferenceTypeTypeParameter
()
&&
parameterType
.
NullableAnnotation
.
IsNotAnnotated
();
// Note: MaybeNull = MaybeNullWhen(true) + MaybeNullWhen(false)
bool
maybeNullWhenTrue
=
(
parameterAnnotations
&
FlowAnalysisAnnotations
.
MaybeNullWhenTrue
)
!=
0
;
...
...
@@ -5153,7 +5157,9 @@ void learnFromPostConditions(BoundExpression argument, FlowAnalysisAnnotations p
{
LearnFromNullTest
(
argument
,
ref
State
);
}
else
if
(
notNullWhenTrue
&&
notNullWhenFalse
&&
!
IsConditionalState
&&
!(
maybeNullWhenTrue
&&
maybeNullWhenFalse
))
else
if
(((
notNullWhenTrue
&&
notNullWhenFalse
)
||
disallowNull
||
setNotNullFromParameterType
)
&&
!
IsConditionalState
&&
!(
maybeNullWhenTrue
||
maybeNullWhenFalse
))
{
LearnFromNonNullTest
(
argument
,
ref
State
);
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
浏览文件 @
53b2957f
此差异已折叠。
点击以展开。
src/Compilers/CSharp/Test/Symbol/Symbols/Source/NullablePublicAPITests.cs
浏览文件 @
53b2957f
...
...
@@ -3001,19 +3001,19 @@ class C<T, U>
{
public T this[U u] { get => throw null!; set => throw null!; }
public static void M(object? o1, object o2)
public static void M(
bool b,
object? o1, object o2)
{
var c1 = CExt.Create(o1, o2);
c1[o1] = o2;
_ = c1[o1];
if (b)
c1[o1] = o2;
if (b)
_ = c1[o1];
var c2 = CExt.Create(o2, o1);
c2[o2] = o1;
_ = c2[o2];
if (b)
c2[o2] = o1;
if (b)
_ = c2[o2];
var c3 = CExt.Create(o1 ?? o2, o2);
c3[o1] = o2;
_ = c3[o1];
if (b)
c3[o1] = o2;
if (b)
_ = c3[o1];
}
}
static class CExt
...
...
@@ -3023,21 +3023,21 @@ static class CExt
var
comp
=
CreateCompilation
(
source
,
options
:
WithNonNullTypesTrue
());
comp
.
VerifyDiagnostics
(
// (9,1
2
): warning CS8604: Possible null reference argument for parameter 'u' in 'object? C<object?, object>.this[object u]'.
// c1[o1] = o2;
Diagnostic
(
ErrorCode
.
WRN_NullReferenceArgument
,
"o1"
).
WithArguments
(
"u"
,
"object? C<object?, object>.this[object u]"
).
WithLocation
(
9
,
1
2
),
// (10,
16
): warning CS8604: Possible null reference argument for parameter 'u' in 'object? C<object?, object>.this[object u]'.
// _ = c1[o1];
Diagnostic
(
ErrorCode
.
WRN_NullReferenceArgument
,
"o1"
).
WithArguments
(
"u"
,
"object? C<object?, object>.this[object u]"
).
WithLocation
(
10
,
16
),
// (13,
18
): warning CS8601: Possible null reference assignment.
// c2[o2] = o1;
Diagnostic
(
ErrorCode
.
WRN_NullReferenceAssignment
,
"o1"
).
WithLocation
(
13
,
18
),
// (17,1
2
): warning CS8604: Possible null reference argument for parameter 'u' in 'object C<object, object>.this[object u]'.
// c3[o1] = o2;
Diagnostic
(
ErrorCode
.
WRN_NullReferenceArgument
,
"o1"
).
WithArguments
(
"u"
,
"object C<object, object>.this[object u]"
).
WithLocation
(
17
,
1
2
),
// (18,
16
): warning CS8604: Possible null reference argument for parameter 'u' in 'object C<object, object>.this[object u]'.
// _ = c3[o1];
Diagnostic
(
ErrorCode
.
WRN_NullReferenceArgument
,
"o1"
).
WithArguments
(
"u"
,
"object C<object, object>.this[object u]"
).
WithLocation
(
18
,
16
));
// (9,1
9
): warning CS8604: Possible null reference argument for parameter 'u' in 'object? C<object?, object>.this[object u]'.
//
if (b)
c1[o1] = o2;
Diagnostic
(
ErrorCode
.
WRN_NullReferenceArgument
,
"o1"
).
WithArguments
(
"u"
,
"object? C<object?, object>.this[object u]"
).
WithLocation
(
9
,
1
9
),
// (10,
23
): warning CS8604: Possible null reference argument for parameter 'u' in 'object? C<object?, object>.this[object u]'.
//
if (b)
_ = c1[o1];
Diagnostic
(
ErrorCode
.
WRN_NullReferenceArgument
,
"o1"
).
WithArguments
(
"u"
,
"object? C<object?, object>.this[object u]"
).
WithLocation
(
10
,
23
),
// (13,
25
): warning CS8601: Possible null reference assignment.
//
if (b)
c2[o2] = o1;
Diagnostic
(
ErrorCode
.
WRN_NullReferenceAssignment
,
"o1"
).
WithLocation
(
13
,
25
),
// (17,1
9
): warning CS8604: Possible null reference argument for parameter 'u' in 'object C<object, object>.this[object u]'.
//
if (b)
c3[o1] = o2;
Diagnostic
(
ErrorCode
.
WRN_NullReferenceArgument
,
"o1"
).
WithArguments
(
"u"
,
"object C<object, object>.this[object u]"
).
WithLocation
(
17
,
1
9
),
// (18,
23
): warning CS8604: Possible null reference argument for parameter 'u' in 'object C<object, object>.this[object u]'.
//
if (b)
_ = c3[o1];
Diagnostic
(
ErrorCode
.
WRN_NullReferenceArgument
,
"o1"
).
WithArguments
(
"u"
,
"object C<object, object>.this[object u]"
).
WithLocation
(
18
,
23
));
var
syntaxTree
=
comp
.
SyntaxTrees
[
0
];
var
root
=
syntaxTree
.
GetRoot
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录