Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b43d3e92
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,发现更多精彩内容 >>
提交
b43d3e92
编写于
3月 08, 2019
作者:
V
vsadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more PR feedback
上级
ef25a749
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
12 deletion
+53
-12
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
+6
-9
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
...rp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+47
-3
未找到文件。
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
浏览文件 @
b43d3e92
...
...
@@ -1430,16 +1430,13 @@ public override BoundNode VisitObjectCreationExpression(BoundObjectCreationExpre
// a nullable value type created with its default constructor is by definition null
resultState
=
NullableFlowState
.
MaybeNull
;
}
else
else
if
(
constructor
.
ParameterCount
==
1
)
{
// if we deal with one-parameter ctor that takes underlying, then Value state is inferred from the argument.
if
(
constructor
.
ParameterCount
==
1
)
var
parameterType
=
constructor
.
ParameterTypes
[
0
];
if
(
AreNullableAndUnderlyingTypes
(
type
,
parameterType
.
TypeSymbol
,
out
TypeSymbolWithAnnotations
underlyingType
))
{
var
parameterType
=
constructor
.
ParameterTypes
[
0
];
if
(
AreNullableAndUnderlyingTypes
(
type
,
parameterType
.
TypeSymbol
,
out
TypeSymbolWithAnnotations
underlyingType
))
{
TrackNullableStateWhenWrappingUnderlying
(
node
,
arguments
[
0
],
type
,
underlyingType
);
}
TrackNullableStateOfNullableValue
(
node
,
arguments
[
0
],
type
,
underlyingType
);
}
}
}
...
...
@@ -3671,11 +3668,11 @@ private void TrackNullableStateIfNullableConversion(BoundConversion node)
if
(
AreNullableAndUnderlyingTypes
(
convertedType
,
operandType
,
out
TypeSymbolWithAnnotations
underlyingType
))
{
// Conversion of T to Nullable<T> is equivalent to new Nullable<T>(t).
TrackNullableState
WhenWrappingUnderlying
(
node
,
operand
,
convertedType
,
underlyingType
);
TrackNullableState
OfNullableValue
(
node
,
operand
,
convertedType
,
underlyingType
);
}
}
private
void
TrackNullableState
WhenWrappingUnderlying
(
BoundExpression
node
,
BoundExpression
operand
,
TypeSymbol
convertedType
,
TypeSymbolWithAnnotations
underlyingType
)
private
void
TrackNullableState
OfNullableValue
(
BoundExpression
node
,
BoundExpression
operand
,
TypeSymbol
convertedType
,
TypeSymbolWithAnnotations
underlyingType
)
{
int
valueSlot
=
MakeSlot
(
operand
);
if
(
valueSlot
>
0
)
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
浏览文件 @
b43d3e92
...
...
@@ -77944,7 +77944,53 @@ static void F()
// (23,9): warning CS8602: Possible dereference of a null reference.
// x.Value.F.ToString(); // warning
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x.Value.F").WithLocation(23, 9)
);
);
}
[WorkItem(32626, "https://github.com/dotnet/roslyn/issues/32626")]
[Fact]
public void NullableCtorErr()
{
var source =
@"
using System;
struct S
{
internal object? F;
}
class Program
{
static void F()
{
S? x = new S() { F = 2 };
x.Value.F.ToString(); // ok baseline
S? y = new Nullable<S>(1);
y.Value.F.ToString(); // warning 1
S? z = new Nullable<S>(null);
z.Value.F.ToString(); // warning 2
}
}
";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (16,32): error CS1503: Argument 1: cannot convert from 'int' to 'S'
// S? y = new Nullable<S>(1);
Diagnostic(ErrorCode.ERR_BadArgType, "1").WithArguments("1", "int", "S").WithLocation(16, 32),
// (17,9): warning CS8602: Possible dereference of a null reference.
// y.Value.F.ToString(); // warning 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "y.Value.F").WithLocation(17, 9),
// (19,32): error CS1503: Argument 1: cannot convert from '<null>' to 'S'
// S? z = new Nullable<S>(null);
Diagnostic(ErrorCode.ERR_BadArgType, "null").WithArguments("1", "<null>", "S").WithLocation(19, 32),
// (20,9): warning CS8602: Possible dereference of a null reference.
// z.Value.F.ToString(); // warning 2
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "z.Value.F").WithLocation(20, 9)
);
}
[WorkItem(32626, "https://github.com/dotnet/roslyn/issues/32626")]
...
...
@@ -77990,8 +78036,6 @@ static void F()
);
}
[Fact]
public void NullableT_AlwaysTrueOrFalse()
{
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录