Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b3049770
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,发现更多精彩内容 >>
未验证
提交
b3049770
编写于
4月 15, 2019
作者:
F
Fred Silberberg
提交者:
GitHub
4月 15, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34926 from 333fred/foreach-loop-variable-mismatch
Correctly report mismatches in foreach types
上级
8a6b522a
e429595f
变更
20
展开全部
隐藏空白更改
内联
并排
Showing
20 changed file
with
315 addition
and
84 deletion
+315
-84
src/Compilers/CSharp/Portable/CSharpResources.resx
src/Compilers/CSharp/Portable/CSharpResources.resx
+6
-0
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
+2
-1
src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
+2
-0
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
+81
-52
src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs
...mpilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs
+1
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
...Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
...Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
+10
-0
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
...rp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+92
-31
src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
...ompilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
+1
-0
未找到文件。
src/Compilers/CSharp/Portable/CSharpResources.resx
浏览文件 @
b3049770
...
...
@@ -5877,4 +5877,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data
name=
"IDS_FeatureObsoleteOnPropertyAccessor"
xml:space=
"preserve"
>
<value>
obsolete on property accessor
</value>
</data>
<data
name=
"WRN_NullReferenceIterationVariable"
xml:space=
"preserve"
>
<value>
Possible null reference assignment to iteration variable
</value>
</data>
<data
name=
"WRN_NullReferenceIterationVariable_Title"
xml:space=
"preserve"
>
<value>
Possible null reference assignment to iteration variable
</value>
</data>
</root>
\ No newline at end of file
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
浏览文件 @
b3049770
...
...
@@ -1634,7 +1634,8 @@ internal enum ErrorCode
WRN_NullReferenceReturn
=
8603
,
WRN_NullReferenceArgument
=
8604
,
WRN_UnboxPossibleNull
=
8605
,
// Unused 8606-8607
WRN_NullReferenceIterationVariable
=
8606
,
// Unused 8607
WRN_NullabilityMismatchInTypeOnOverride
=
8608
,
WRN_NullabilityMismatchInReturnTypeOnOverride
=
8609
,
WRN_NullabilityMismatchInParameterTypeOnOverride
=
8610
,
...
...
src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
浏览文件 @
b3049770
...
...
@@ -25,6 +25,7 @@ static ErrorFacts()
builder
.
Add
(
getId
(
ErrorCode
.
WRN_NullReferenceReceiver
));
builder
.
Add
(
getId
(
ErrorCode
.
WRN_NullReferenceReturn
));
builder
.
Add
(
getId
(
ErrorCode
.
WRN_NullReferenceArgument
));
builder
.
Add
(
getId
(
ErrorCode
.
WRN_NullReferenceIterationVariable
));
builder
.
Add
(
getId
(
ErrorCode
.
WRN_UninitializedNonNullableField
));
builder
.
Add
(
getId
(
ErrorCode
.
WRN_NullabilityMismatchInAssignment
));
builder
.
Add
(
getId
(
ErrorCode
.
WRN_NullabilityMismatchInArgument
));
...
...
@@ -370,6 +371,7 @@ internal static int GetWarningLevel(ErrorCode code)
case
ErrorCode
.
WRN_NullReferenceReceiver
:
case
ErrorCode
.
WRN_NullReferenceReturn
:
case
ErrorCode
.
WRN_NullReferenceArgument
:
case
ErrorCode
.
WRN_NullReferenceIterationVariable
:
case
ErrorCode
.
WRN_NullabilityMismatchInTypeOnOverride
:
case
ErrorCode
.
WRN_NullabilityMismatchInReturnTypeOnOverride
:
case
ErrorCode
.
WRN_NullabilityMismatchInParameterTypeOnOverride
:
...
...
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
浏览文件 @
b3049770
此差异已折叠。
点击以展开。
src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs
浏览文件 @
b3049770
...
...
@@ -194,6 +194,7 @@ public static bool IsWarning(ErrorCode code)
case
ErrorCode
.
WRN_NullReferenceReturn
:
case
ErrorCode
.
WRN_NullReferenceArgument
:
case
ErrorCode
.
WRN_UnboxPossibleNull
:
case
ErrorCode
.
WRN_NullReferenceIterationVariable
:
case
ErrorCode
.
WRN_NullabilityMismatchInTypeOnOverride
:
case
ErrorCode
.
WRN_NullabilityMismatchInReturnTypeOnOverride
:
case
ErrorCode
.
WRN_NullabilityMismatchInParameterTypeOnOverride
:
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target state="translated">Může jít o přiřazení s odkazem null.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Může jít o vyhodnocení odkazu null.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target state="translated">Mögliche Nullverweiszuweisung.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Mögliche Dereferenzierung eines Nullverweises.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
浏览文件 @
b3049770
...
...
@@ -1424,6 +1424,16 @@
<target state="translated">Posible asignación de referencia nula</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Posible desreferencia de una referencia nula.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
浏览文件 @
b3049770
...
...
@@ -1423,6 +1423,16 @@
<target state="translated">Existence possible d'une assignation de référence null.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Déréférencement possible d'une référence null.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target state="translated">Possibile assegnazione di riferimento Null.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Possibile dereferenziamento di un riferimento Null.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target state="translated">Null 参照割り当ての可能性があります。</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Null 参照の逆参照である可能性があります。</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target state="translated">가능한 null 참조 할당입니다.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">가능한 null 참조의 역참조입니다.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target state="translated">Możliwe przypisanie odwołania o wartości null.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Możliwe wyłuskanie odwołania o wartości null.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target state="translated">Possível atribuição de referência nula.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Possível desreferência de uma referência nula.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target state="translated">Возможно, присваивание-ссылка, допускающее значение NULL.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Возможно, разыменование ссылки, допускающей значение NULL.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
浏览文件 @
b3049770
...
...
@@ -1423,6 +1423,16 @@
<target state="translated">Olası null başvuru ataması.</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceIterationVariable_Title">
<source>Possible null reference assignment to iteration variable</source>
<target state="new">Possible null reference assignment to iteration variable</target>
<note />
</trans-unit>
<trans-unit id="WRN_NullReferenceReceiver">
<source>Dereference of a possibly null reference.</source>
<target state="needs-review-translation">Null başvuruya yönelik olası başvuru.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
浏览文件 @
b3049770
...
...
@@ -1463,6 +1463,16 @@
<target
state=
"translated"
>
可能的 null 引用赋值。
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"WRN_NullReferenceIterationVariable"
>
<source>
Possible null reference assignment to iteration variable
</source>
<target
state=
"new"
>
Possible null reference assignment to iteration variable
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"WRN_NullReferenceIterationVariable_Title"
>
<source>
Possible null reference assignment to iteration variable
</source>
<target
state=
"new"
>
Possible null reference assignment to iteration variable
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"WRN_NullReferenceReceiver"
>
<source>
Dereference of a possibly null reference.
</source>
<target
state=
"needs-review-translation"
>
null 引用可能的取消引用。
</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
浏览文件 @
b3049770
...
...
@@ -1422,6 +1422,16 @@
<target
state=
"translated"
>
可能有 Null 參考指派。
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"WRN_NullReferenceIterationVariable"
>
<source>
Possible null reference assignment to iteration variable
</source>
<target
state=
"new"
>
Possible null reference assignment to iteration variable
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"WRN_NullReferenceIterationVariable_Title"
>
<source>
Possible null reference assignment to iteration variable
</source>
<target
state=
"new"
>
Possible null reference assignment to iteration variable
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"WRN_NullReferenceReceiver"
>
<source>
Dereference of a possibly null reference.
</source>
<target
state=
"needs-review-translation"
>
可能有 Null 參考的取值 (Dereference)。
</target>
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
浏览文件 @
b3049770
...
...
@@ -33753,8 +33753,15 @@ static void G()
}
}";
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
// https://github.com/dotnet/roslyn/issues/33011: Deconstruction should infer `string?` for `var y`.
comp.VerifyDiagnostics();
// https://github.com/dotnet/roslyn/issues/33011: Deconstruction should infer `string?` for `var y`. Shouldn't report nullability
// mismatches
comp.VerifyDiagnostics(
// (8,18): warning CS8619: Nullability of reference types in value of type '(string, string?)' doesn't match target type 'string'.
// foreach ((var x, var y) in F())
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "(var x, var y)").WithArguments("(string, string?)", "string").WithLocation(8, 18),
// (8,18): warning CS8619: Nullability of reference types in value of type '(string, string?)' doesn't match target type 'string'.
// foreach ((var x, var y) in F())
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "(var x, var y)").WithArguments("(string, string?)", "string").WithLocation(8, 18));
//// (11,13): warning CS8602: Dereference of a possibly null reference.
//// y.ToString();
//Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "y").WithLocation(11, 13));
...
...
@@ -50456,11 +50463,14 @@ static void F(Enumerable e)
foreach (string y in e)
y.ToString();
foreach (string? z in e)
z.ToString();
z.ToString();
// 1
}
}";
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics();
comp.VerifyDiagnostics(
// (19,13): warning CS8602: Dereference of a possibly null reference.
// z.ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "z").WithLocation(19, 13));
}
[Fact]
...
...
@@ -50493,9 +50503,9 @@ static void F(Enumerable e)
// (15,13): warning CS8602: Dereference of a possibly null reference.
// x.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(15, 13),
// (16,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (16,
25): warning CS8605: Possible null reference assignment to iteration variable
// foreach (object y in e)
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "object").WithLocation(16, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "y").WithLocation(16, 25
),
// (17,13): warning CS8602: Dereference of a possibly null reference.
// y.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "y").WithLocation(17, 13),
...
...
@@ -50574,18 +50584,18 @@ static void G(IEnumerable e)
// (50,13): warning CS8602: Dereference of a possibly null reference.
// x.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(50, 13),
// (51,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (51,
25): warning CS8605: Possible null reference assignment to iteration variable
// foreach (object y in e)
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "object").WithLocation(51, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "y").WithLocation(51, 25
),
// (52,13): warning CS8602: Dereference of a possibly null reference.
// y.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "y").WithLocation(52, 13),
// (57,13): warning CS8602: Dereference of a possibly null reference.
// z.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "z").WithLocation(57, 13),
// (58,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (58,
25): warning CS8605: Possible null reference assignment to iteration variable
// foreach (object w in e)
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "object").WithLocation(58, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "w").WithLocation(58, 25
),
// (59,13): warning CS8602: Dereference of a possibly null reference.
// w.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "w").WithLocation(59, 13));
...
...
@@ -50674,15 +50684,15 @@ class P
// (15,13): warning CS8602: Dereference of a possibly null reference.
// y.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "y").WithLocation(15, 13),
// (16,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (16,
20): warning CS8605: Possible null reference assignment to iteration variable
// foreach (T z in c)
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "T").WithLocation(16, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "z").WithLocation(16, 20
),
// (17,13): warning CS8602: Dereference of a possibly null reference.
// z.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "z").WithLocation(17, 13),
// (18,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (18,
25): warning CS8605: Possible null reference assignment to iteration variable
// foreach (object w in c)
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "object").WithLocation(18, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "w").WithLocation(18, 25
),
// (19,13): warning CS8602: Dereference of a possibly null reference.
// w.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "w").WithLocation(19, 13));
...
...
@@ -50734,9 +50744,9 @@ class P
// (26,13): warning CS8602: Dereference of a possibly null reference.
// x2.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x2").WithLocation(26, 13),
// (27,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (27,
20): warning CS8605: Possible null reference assignment to iteration variable
// foreach (T y2 in new S<T?>())
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "T").WithLocation(27, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "y2").WithLocation(27, 20
),
// (27,32): warning CS8634: The type 'T?' cannot be used as type parameter 'T' in the generic type or method 'S<T>'. Nullability of type argument 'T?' doesn't match 'class' constraint.
// foreach (T y2 in new S<T?>())
Diagnostic(ErrorCode.WRN_NullabilityMismatchInTypeParameterReferenceTypeConstraint, "T?").WithArguments("S<T>", "T", "T?").WithLocation(27, 32),
...
...
@@ -50791,12 +50801,24 @@ static void F3(IEnumerable<IOut<object>> x3, IEnumerable<IOut<object?>> y3)
}";
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (9,29): warning CS8619: Nullability of reference types in value of type 'I<object>' doesn't match target type 'I<object?>'.
// foreach (I<object?> a1 in x1)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "a1").WithArguments("I<object>", "I<object?>").WithLocation(9, 29),
// (10,13): warning CS8602: Dereference of a possibly null reference.
// a1.P.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a1.P").WithLocation(10, 13),
// (11,28): warning CS8619: Nullability of reference types in value of type 'I<object?>' doesn't match target type 'I<object>'.
// foreach (I<object> b1 in y1)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b1").WithArguments("I<object?>", "I<object>").WithLocation(11, 28),
// (16,31): warning CS8619: Nullability of reference types in value of type 'IIn<object>' doesn't match target type 'IIn<object?>'.
// foreach (IIn<object?> a2 in x2)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "a2").WithArguments("IIn<object>", "IIn<object?>").WithLocation(16, 31),
// (24,13): warning CS8602: Dereference of a possibly null reference.
// a3.P.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a3.P").WithLocation(24, 13));
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a3.P").WithLocation(24, 13),
// (25,31): warning CS8619: Nullability of reference types in value of type 'IOut<object?>' doesn't match target type 'IOut<object>'.
// foreach (IOut<object> b3 in y3)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b3").WithArguments("IOut<object?>", "IOut<object>").WithLocation(25, 31));
}
[Fact]
...
...
@@ -50829,18 +50851,18 @@ static void F(A?[] c)
// (10,13): warning CS8602: Dereference of a possibly null reference.
// a2.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a2").WithLocation(10, 13),
// (11,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (11,
20): warning CS8605: Possible null reference assignment to iteration variable
// foreach (A a3 in c)
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "A").WithLocation(11, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "a3").WithLocation(11, 20
),
// (12,13): warning CS8602: Dereference of a possibly null reference.
// a3.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a3").WithLocation(12, 13),
// (14,13): warning CS8602: Dereference of a possibly null reference.
// b1.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b1").WithLocation(14, 13),
// (15,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (15,
20): warning CS8605: Possible null reference assignment to iteration variable
// foreach (B b2 in c)
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "B").WithLocation(15, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "b2").WithLocation(15, 20
),
// (16,13): warning CS8602: Dereference of a possibly null reference.
// b2.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b2").WithLocation(16, 13));
...
...
@@ -50872,8 +50894,6 @@ static void F(A<object?>[] c)
b1.ToString();
}
}";
// https://github.com/dotnet/roslyn/issues/29971: Should report WRN_NullabilityMismatchInAssignment
// for `A<object> a3 in c` and `B b1 in c`.
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (13,13): warning CS8602: Dereference of a possibly null reference.
...
...
@@ -50881,10 +50901,17 @@ static void F(A<object?>[] c)
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a1.F").WithLocation(13, 13),
// (15,13): warning CS8602: Dereference of a possibly null reference.
// a2.F.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a2.F").WithLocation(15, 13));
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a2.F").WithLocation(15, 13),
// (16,28): warning CS8619: Nullability of reference types in value of type 'A<object?>' doesn't match target type 'A<object>'.
// foreach (A<object> a3 in c)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "a3").WithArguments("A<object?>", "A<object>").WithLocation(16, 28),
// (18,20): warning CS8619: Nullability of reference types in value of type 'A<object?>' doesn't match target type 'B'.
// foreach (B b1 in c)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b1").WithArguments("A<object?>", "B").WithLocation(18, 20));
}
[Fact]
[WorkItem(29971, "https://github.com/dotnet/roslyn/issues/29971")]
public void ForEach_11()
{
var source =
...
...
@@ -50912,18 +50939,16 @@ static void F(IEnumerable<A> e)
}
}";
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
// https://github.com/dotnet/roslyn/issues/29971: Location of WRN_ConvertingNullableToNonNullable should be `y` rather than `B`.
comp.VerifyDiagnostics(
// (15,
18): warning CS8600: Converting null literal or possible null value to non-nullable type.
// (15,
20): warning CS8605: Possible null reference assignment to iteration variable
// foreach (B y in e)
Diagnostic(ErrorCode.WRN_
ConvertingNullableToNonNullable, "B").WithLocation(15, 18
),
Diagnostic(ErrorCode.WRN_
NullReferenceIterationVariable, "y").WithLocation(15, 20
),
// (16,13): warning CS8602: Dereference of a possibly null reference.
// y.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "y").WithLocation(16, 13),
// (19,13): warning CS8602: Dereference of a possibly null reference.
// z.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "z").WithLocation(19, 13)
);
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "z").WithLocation(19, 13));
}
[WorkItem(23493, "https://github.com/dotnet/roslyn/issues/23493")]
...
...
@@ -85636,10 +85661,46 @@ static void F1<T>(IEnumerable<(T, T)> e1)
z3.ToString(); // 8
}
}
static void F4((object?, object?)[] arr)
{
foreach ((object, object) el in arr) // 9
{
el.Item1.ToString();
el.Item2.ToString();
}
foreach ((object i1, object i2) in arr) // 10, 11
{
i1.ToString(); // 12
i2.ToString(); // 13
}
}
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
// https://github.com/dotnet/roslyn/issues/33017: Report warnings.
comp.VerifyDiagnostics();
// https://github.com/dotnet/roslyn/issues/33017: Report warnings for null dereferences,
// stop reporting warnings for the type mismatches on var. 10 and 11 should probably be W warnings?
comp.VerifyDiagnostics(
// (6,18): warning CS8619: Nullability of reference types in value of type '(T, T)' doesn't match target type 'T'.
// foreach (var (x1, y1) in e1)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "var (x1, y1)").WithArguments("(T, T)", "T").WithLocation(6, 18),
// (6,18): warning CS8619: Nullability of reference types in value of type '(T, T)' doesn't match target type 'T'.
// foreach (var (x1, y1) in e1)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "var (x1, y1)").WithArguments("(T, T)", "T").WithLocation(6, 18),
// (19,18): warning CS8619: Nullability of reference types in value of type '(T, T?)' doesn't match target type 'T'.
// foreach (var (x2, y2) in e2)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "var (x2, y2)").WithArguments("(T, T?)", "T").WithLocation(19, 18),
// (19,18): warning CS8619: Nullability of reference types in value of type '(T, T?)' doesn't match target type 'T'.
// foreach (var (x2, y2) in e2)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "var (x2, y2)").WithArguments("(T, T?)", "T").WithLocation(19, 18),
// (32,18): warning CS8619: Nullability of reference types in value of type '(T, T?)' doesn't match target type 'T'.
// foreach (var (x3, y3) in e3)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "var (x3, y3)").WithArguments("(T, T?)", "T").WithLocation(32, 18),
// (32,18): warning CS8619: Nullability of reference types in value of type '(T, T?)' doesn't match target type 'T?'.
// foreach (var (x3, y3) in e3)
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "var (x3, y3)").WithArguments("(T, T?)", "T?").WithLocation(32, 18),
// (45,35): warning CS8619: Nullability of reference types in value of type '(object?, object?)' doesn't match target type '(object, object)'.
// foreach ((object, object) el in arr) // 9
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "el").WithArguments("(object?, object?)", "(object, object)").WithLocation(45, 35));
}
[Fact]
src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
浏览文件 @
b3049770
...
...
@@ -269,6 +269,7 @@ public void WarningLevel_2()
case
ErrorCode
.
WRN_NullReferenceReceiver
:
case
ErrorCode
.
WRN_NullReferenceReturn
:
case
ErrorCode
.
WRN_NullReferenceArgument
:
case
ErrorCode
.
WRN_NullReferenceIterationVariable
:
case
ErrorCode
.
WRN_NullabilityMismatchInTypeOnOverride
:
case
ErrorCode
.
WRN_NullabilityMismatchInReturnTypeOnOverride
:
case
ErrorCode
.
WRN_NullabilityMismatchInParameterTypeOnOverride
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录