Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3e5decb2
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,发现更多精彩内容 >>
未验证
提交
3e5decb2
编写于
7月 27, 2020
作者:
J
Julien Couvreur
提交者:
GitHub
7月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Relax enforcement on conditional nullability attributes (#46201)
上级
71e720ec
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
56 deletion
+48
-56
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
+0
-10
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
...rp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+48
-46
未找到文件。
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
浏览文件 @
3e5decb2
...
...
@@ -502,11 +502,6 @@ void enforceMemberNotNullWhenForPendingReturn(PendingBranch pendingReturn, Bound
enforceMemberNotNullWhen
(
returnStatement
.
Syntax
,
sense
:
true
,
pendingReturn
.
StateWhenTrue
);
enforceMemberNotNullWhen
(
returnStatement
.
Syntax
,
sense
:
false
,
pendingReturn
.
StateWhenFalse
);
}
else
{
enforceMemberNotNullWhen
(
returnStatement
.
Syntax
,
sense
:
true
,
pendingReturn
.
State
);
enforceMemberNotNullWhen
(
returnStatement
.
Syntax
,
sense
:
false
,
pendingReturn
.
State
);
}
}
void
enforceMemberNotNullWhen
(
SyntaxNode
syntaxOpt
,
bool
sense
,
LocalState
state
)
...
...
@@ -605,11 +600,6 @@ void enforceNotNullWhenForPendingReturn(PendingBranch pendingReturn, BoundExpres
enforceParameterNotNullWhen
(
returnStatement
.
Syntax
,
parameters
,
sense
:
true
,
stateWhen
:
pendingReturn
.
StateWhenTrue
);
enforceParameterNotNullWhen
(
returnStatement
.
Syntax
,
parameters
,
sense
:
false
,
stateWhen
:
pendingReturn
.
StateWhenFalse
);
}
else
{
enforceParameterNotNullWhen
(
returnStatement
.
Syntax
,
parameters
,
sense
:
true
,
stateWhen
:
pendingReturn
.
State
);
enforceParameterNotNullWhen
(
returnStatement
.
Syntax
,
parameters
,
sense
:
false
,
stateWhen
:
pendingReturn
.
State
);
}
}
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
浏览文件 @
3e5decb2
...
...
@@ -22385,7 +22385,7 @@ public class C
bool Init()
{
bool b = true;
return b;
// 2
return b;
}
}
", MemberNotNullWhenAttributeDefinition }, parseOptions: TestOptions.RegularPreview);
...
...
@@ -22393,10 +22393,7 @@ bool Init()
c.VerifyDiagnostics(
// (5,19): warning CS8618: Non-nullable field 'field1' is uninitialized. Consider declaring the field as nullable.
// public string field1; // 1
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "field1").WithArguments("field", "field1").WithLocation(5, 19),
// (11,9): warning CS8775: Member 'field1' must have a non-null value when exiting with 'true'.
// return b; // 2
Diagnostic(ErrorCode.WRN_MemberNotNullWhen, "return b;").WithArguments("field1", "true").WithLocation(11, 9)
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "field1").WithArguments("field", "field1").WithLocation(5, 19)
);
}
...
...
@@ -23798,7 +23795,7 @@ bool Init(bool b)
);
}
[Fact]
[Fact
, WorkItem(44080, "https://github.com/dotnet/roslyn/issues/44080")
]
public void MemberNotNullWhenTrue_EnforcedInMethodBody_NonConstantBool()
{
var c = CreateNullableCompilation(new[] { @"
...
...
@@ -23822,13 +23819,7 @@ bool Init()
c.VerifyDiagnostics(
// (5,19): warning CS8618: Non-nullable field 'field1' is uninitialized. Consider declaring the field as nullable.
// public string field1;
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "field1").WithArguments("field", "field1").WithLocation(5, 19),
// (13,9): warning CS8775: Member 'field1' must have a non-null value when exiting with 'true'.
// return NonConstantBool();
Diagnostic(ErrorCode.WRN_MemberNotNullWhen, "return NonConstantBool();").WithArguments("field1", "true").WithLocation(13, 9),
// (13,9): warning CS8775: Member 'field3' must have a non-null value when exiting with 'true'.
// return NonConstantBool();
Diagnostic(ErrorCode.WRN_MemberNotNullWhen, "return NonConstantBool();").WithArguments("field3", "true").WithLocation(13, 9)
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "field1").WithArguments("field", "field1").WithLocation(5, 19)
);
}
...
...
@@ -24613,11 +24604,7 @@ public static bool TryGetValue<T>([MaybeNull] [NotNullWhen(true)] out T t)
}
";
var comp = CreateNullableCompilation(new[] { source, MaybeNullAttributeDefinition, NotNullWhenAttributeDefinition });
comp.VerifyDiagnostics(
// (7,9): warning CS8762: Parameter 't' must have a non-null value when exiting with 'true'.
// return TryGetValue2<T>(out t);
Diagnostic(ErrorCode.WRN_ParameterConditionallyDisallowsNull, "return TryGetValue2<T>(out t);").WithArguments("t", "true").WithLocation(7, 9)
);
comp.VerifyDiagnostics();
}
[Fact, WorkItem(39922, "https://github.com/dotnet/roslyn/issues/39922")]
...
...
@@ -24826,20 +24813,16 @@ public class C
public static bool TryGetValue([NotNullWhen(true)] out string? s)
{
s = null;
return NonConstantBool();
// 1
return NonConstantBool();
}
static bool NonConstantBool() => throw null!;
}
";
var comp = CreateNullableCompilation(new[] { source, NotNullWhenAttributeDefinition });
comp.VerifyDiagnostics(
// (8,9): warning CS8762: Parameter 's' must have a non-null value when exiting with 'true'.
// return NonConstantBool(); // 1
Diagnostic(ErrorCode.WRN_ParameterConditionallyDisallowsNull, "return NonConstantBool();").WithArguments("s", "true").WithLocation(8, 9)
);
comp.VerifyDiagnostics();
}
[Fact, WorkItem(39922, "https://github.com/dotnet/roslyn/issues/39922")]
[Fact, WorkItem(39922, "https://github.com/dotnet/roslyn/issues/39922")
, WorkItem(44080, "https://github.com/dotnet/roslyn/issues/44080")
]
public void NotNullWhenFalse_EnforceInMethodBody_Warn_NonConstantReturn()
{
var source = @"
...
...
@@ -24849,17 +24832,13 @@ public class C
public static bool TryGetValue([NotNullWhen(false)] out string? s)
{
s = null;
return NonConstantBool();
// 1
return NonConstantBool();
}
static bool NonConstantBool() => throw null!;
}
";
var comp = CreateNullableCompilation(new[] { source, NotNullWhenAttributeDefinition });
comp.VerifyDiagnostics(
// (8,9): warning CS8762: Parameter 's' must have a non-null value when exiting with 'false'.
// return NonConstantBool(); // 1
Diagnostic(ErrorCode.WRN_ParameterConditionallyDisallowsNull, "return NonConstantBool();").WithArguments("s", "false").WithLocation(8, 9)
);
comp.VerifyDiagnostics();
}
[Fact, WorkItem(39922, "https://github.com/dotnet/roslyn/issues/39922"), WorkItem(42386, "https://github.com/dotnet/roslyn/issues/42386")]
...
...
@@ -25019,7 +24998,7 @@ public static bool TryGetValue(C? c, [NotNullWhen(true)] out string? s)
return c; // 1
}
public static bool TryGetValue2(C c, [NotNullWhen(
tru
e)] out string? s)
public static bool TryGetValue2(C c, [NotNullWhen(
fals
e)] out string? s)
{
s = null;
return c; // 2
...
...
@@ -25041,20 +25020,7 @@ static bool TryGetValue4([MaybeNullWhen(false)]out string s)
}
";
var comp = CreateNullableCompilation(new[] { source, NotNullWhenAttributeDefinition, MaybeNullWhenAttributeDefinition });
comp.VerifyDiagnostics(
// (8,9): warning CS8762: Parameter 's' must have a non-null value when exiting with 'true'.
// return c; // 1
Diagnostic(ErrorCode.WRN_ParameterConditionallyDisallowsNull, "return c;").WithArguments("s", "true").WithLocation(8, 9),
// (14,9): warning CS8762: Parameter 's' must have a non-null value when exiting with 'true'.
// return c; // 2
Diagnostic(ErrorCode.WRN_ParameterConditionallyDisallowsNull, "return c;").WithArguments("s", "true").WithLocation(14, 9),
// (22,9): warning CS8762: Parameter 's' must have a non-null value when exiting with 'true'.
// return (bool)true; // 3
Diagnostic(ErrorCode.WRN_ParameterConditionallyDisallowsNull, "return (bool)true;").WithArguments("s", "true").WithLocation(22, 9),
// (28,9): warning CS8762: Parameter 's' must have a non-null value when exiting with 'true'.
// return (bool)false; // 4
Diagnostic(ErrorCode.WRN_ParameterConditionallyDisallowsNull, "return (bool)false;").WithArguments("s", "true").WithLocation(28, 9)
);
comp.VerifyDiagnostics();
}
[Fact]
...
...
@@ -133746,6 +133712,42 @@ public new void M1<T>(System.Nullable<T?> x)
);
}
[Fact, WorkItem(43071, "https://github.com/dotnet/roslyn/issues/43071")]
public void LocalFunctionInLambdaWithReturnStatement()
{
var source = @"
using System;
using System.Collections.Generic;
public class C<T>
{
public static C<string> ReproFunction(C<string> collection)
{
return collection
.SelectMany(allStrings =>
{
return new[] { getSomeString(""custard"") };
string getSomeString(string substring)
{
return substring;
}
});
}
}
public static class Extension
{
public static C<TResult> SelectMany<TSource, TResult>(this C<TSource> source, Func<TSource, IEnumerable<TResult>> selector)
{
throw null!;
}
}
";
var comp = CreateNullableCompilation(source);
comp.VerifyDiagnostics();
}
[Fact]
[WorkItem(44348, "https://github.com/dotnet/roslyn/issues/44348")]
public void Constraints()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录