Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
e128267a
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,发现更多精彩内容 >>
未验证
提交
e128267a
编写于
7月 27, 2020
作者:
C
Charles Stoner
提交者:
GitHub
7月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix TypeWithAnnotations.ToTypeWithState() for (untyped) null literal (#46344)
上级
dee18a34
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
163 addition
and
10 deletion
+163
-10
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
...inder/Semantics/OverloadResolution/MethodTypeInference.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
+4
-5
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
...rp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+158
-4
未找到文件。
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
浏览文件 @
e128267a
...
...
@@ -1542,7 +1542,7 @@ private bool ExactOrBoundsNullableInference(ExactOrBoundsKind kind, TypeWithAnno
return
false
;
// True if the type is nullable.
bool
isNullableOnly
(
TypeWithAnnotations
type
)
static
bool
isNullableOnly
(
TypeWithAnnotations
type
)
=>
type
.
NullableAnnotation
.
IsAnnotated
();
}
...
...
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
浏览文件 @
e128267a
...
...
@@ -772,11 +772,6 @@ internal bool IsSameAs(TypeWithAnnotations other)
/// </summary>
internal
TypeWithState
ToTypeWithState
()
{
if
(
Type
is
null
)
{
return
default
;
}
// This operation reflects reading from an lvalue, which produces an rvalue.
// Reading from a variable of a type parameter (that could be substituted with a nullable type), but which
// cannot itself be annotated (because it isn't known to be a reference type), may yield a null value
...
...
@@ -785,6 +780,10 @@ internal TypeWithState ToTypeWithState()
static
NullableFlowState
getFlowState
(
TypeSymbol
type
,
NullableAnnotation
annotation
)
{
if
(
type
is
null
)
{
return
annotation
.
IsAnnotated
()
?
NullableFlowState
.
MaybeNull
:
NullableFlowState
.
NotNull
;
}
if
(
type
.
IsPossiblyNullableReferenceTypeTypeParameter
())
{
return
annotation
switch
{
NullableAnnotation
.
Annotated
=>
NullableFlowState
.
MaybeDefault
,
NullableAnnotation
.
NotAnnotated
=>
NullableFlowState
.
MaybeNull
,
_
=>
NullableFlowState
.
NotNull
};
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
浏览文件 @
e128267a
...
...
@@ -51082,12 +51082,12 @@ static void G(string x)
new[] { source }, options: WithNonNullTypesTrue(),
parseOptions: TestOptions.Regular8);
comp.VerifyDiagnostics(
// (9,
54): warning CS8603: Possible null reference return
.
// (9,
9): warning CS8602: Dereference of a possibly null reference
.
// F(() => { if (x.Length > 0) return x; return null; }).ToString();
Diagnostic(ErrorCode.WRN_NullReferenceRe
turn, "null").WithLocation(9, 54
),
// (10,
45): warning CS8603: Possible null reference return
.
Diagnostic(ErrorCode.WRN_NullReferenceRe
ceiver, "F(() => { if (x.Length > 0) return x; return null; })").WithLocation(9, 9
),
// (10,
9): warning CS8602: Dereference of a possibly null reference
.
// F(() => { if (x.Length == 0) return null; return x; }).ToString();
Diagnostic(ErrorCode.WRN_NullReferenceRe
turn, "null").WithLocation(10, 45
));
Diagnostic(ErrorCode.WRN_NullReferenceRe
ceiver, "F(() => { if (x.Length == 0) return null; return x; })").WithLocation(10, 9
));
}
[Fact]
...
...
@@ -133331,6 +133331,160 @@ internal interface IB : IA { }
comp.VerifyEmitDiagnostics();
}
[Fact]
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")]
public void LambdaNullReturn_01()
{
var source =
@"#nullable enable
using System;
class Program
{
static void F<T>(Func<T> f)
{
}
static void M<T>(bool b, T t) where T : class
{
F(() =>
{
if (b) return null;
return t;
});
}
}";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics();
}
[Fact]
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")]
public void LambdaNullReturn_02()
{
var source =
@"#nullable enable
using System;
class Program
{
static void F<T>(Func<T> f)
{
}
static void M<T>(bool b, T t) where T : class?
{
F(() =>
{
if (b) return null;
return t;
});
}
}";
var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview);
comp.VerifyEmitDiagnostics();
}
[Fact]
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")]
public void LambdaNullReturn_03()
{
var source =
@"#nullable enable
using System;
class Program
{
static void F<T>(Func<T> f)
{
}
static void M<T>(T? t) where T : class
{
F(() =>
{
if (t is null) return null;
return t;
});
}
}";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics();
}
[Fact]
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")]
public void LambdaNullReturn_04()
{
var source =
@"#nullable enable
using System;
class Program
{
static void F<T>(Func<T> f)
{
}
static void M<T>(T? t) where T : class?
{
F(() =>
{
if (t is null) return null;
return t;
});
}
}";
var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview);
comp.VerifyEmitDiagnostics();
}
[Fact]
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")]
public void LambdaNullReturn_05()
{
var source =
@"#nullable enable
using System;
using System.Threading.Tasks;
class Program
{
static void F<T>(Func<Task<T>> f)
{
}
static void M<T>(T? t) where T : class
{
F(async () =>
{
await Task.Yield();
if (t is null) return null;
return t;
});
}
}";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics();
}
[Fact]
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")]
public void LambdaNullReturn_06()
{
var source =
@"#nullable enable
using System;
using System.Threading.Tasks;
class Program
{
static void F<T>(Func<Task<T>> f)
{
}
static void M<T>(T? t) where T : class?
{
F(async () =>
{
await Task.Yield();
if (t is null) return null;
return t;
});
}
}";
var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview);
comp.VerifyEmitDiagnostics();
}
[Fact]
[WorkItem(45862, "https://github.com/dotnet/roslyn/issues/45862")]
public void Issue_45862()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录