Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
90590524
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,发现更多精彩内容 >>
未验证
提交
90590524
编写于
5月 16, 2019
作者:
R
Rikki Gibson
提交者:
GitHub
5月 16, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #35273 from RikkiGibson/cherry-pick-34909
Cherry-pick PR #34909
上级
77bf98b4
6a6541f5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
37 addition
and
50 deletion
+37
-50
src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
...ompilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
+3
-3
src/Compilers/CSharp/Portable/Symbols/ExtraAnnotations.cs
src/Compilers/CSharp/Portable/Symbols/ExtraAnnotations.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs
...arp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs
+3
-3
src/Compilers/CSharp/Portable/Symbols/NullableAnnotation.cs
src/Compilers/CSharp/Portable/Symbols/NullableAnnotation.cs
+5
-5
src/Compilers/CSharp/Portable/Symbols/NullableAnnotationExtensions.cs
...s/CSharp/Portable/Symbols/NullableAnnotationExtensions.cs
+18
-31
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
+7
-7
未找到文件。
src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
浏览文件 @
90590524
...
...
@@ -1497,14 +1497,14 @@ internal SynthesizedAttributeData SynthesizeNullableAttribute(Symbol symbol, Typ
type
.
AddNullableTransforms
(
flagsBuilder
);
Debug
.
Assert
(
flagsBuilder
.
Any
());
Debug
.
Assert
(
flagsBuilder
.
Contains
(
(
byte
)
NullableAnnotation
.
NotAnnotated
)
||
flagsBuilder
.
Contains
((
byte
)
NullableAnnotation
.
Annotated
));
Debug
.
Assert
(
flagsBuilder
.
Contains
(
NullableAnnotationExtensions
.
NotAnnotatedAttributeValue
)
||
flagsBuilder
.
Contains
(
NullableAnnotationExtensions
.
AnnotatedAttributeValue
));
WellKnownMember
constructor
;
ImmutableArray
<
TypedConstant
>
arguments
;
NamedTypeSymbol
byteType
=
Compilation
.
GetSpecialType
(
SpecialType
.
System_Byte
);
Debug
.
Assert
((
object
)
byteType
!=
null
);
if
(
flagsBuilder
.
All
(
flag
=>
flag
==
(
byte
)
NullableAnnotation
.
NotAnnotated
)
||
flagsBuilder
.
All
(
flag
=>
flag
==
(
byte
)
NullableAnnotation
.
Annotated
))
if
(
flagsBuilder
.
All
(
flag
=>
flag
==
NullableAnnotationExtensions
.
NotAnnotatedAttributeValue
)
||
flagsBuilder
.
All
(
flag
=>
flag
==
NullableAnnotationExtensions
.
AnnotatedAttributeValue
))
{
constructor
=
WellKnownMember
.
System_Runtime_CompilerServices_NullableAttribute__ctorByte
;
arguments
=
ImmutableArray
.
Create
(
new
TypedConstant
(
byteType
,
TypedConstantKind
.
Primitive
,
flagsBuilder
[
0
]));
...
...
@@ -1515,7 +1515,7 @@ internal SynthesizedAttributeData SynthesizeNullableAttribute(Symbol symbol, Typ
foreach
(
byte
flag
in
flagsBuilder
)
{
Debug
.
Assert
(
flag
==
(
byte
)
NullableAnnotation
.
Oblivious
||
flag
==
(
byte
)
NullableAnnotation
.
NotAnnotated
||
flag
==
(
byte
)
NullableAnnotation
.
Annotated
);
Debug
.
Assert
(
flag
==
NullableAnnotationExtensions
.
ObliviousAttributeValue
||
flag
==
NullableAnnotationExtensions
.
NotAnnotatedAttributeValue
||
flag
==
NullableAnnotationExtensions
.
AnnotatedAttributeValue
);
constantsBuilder
.
Add
(
new
TypedConstant
(
byteType
,
TypedConstantKind
.
Primitive
,
flag
));
}
...
...
src/Compilers/CSharp/Portable/Symbols/ExtraAnnotations.cs
浏览文件 @
90590524
...
...
@@ -129,7 +129,7 @@ private static ImmutableArray<FlowAnalysisAnnotations> Array(params FlowAnalysis
private
static
ImmutableArray
<
byte
>
Nullable
(
bool
isNullable
)
{
return
ImmutableArray
.
Create
(
(
byte
)(
isNullable
?
NullableAnnotation
.
Annotated
:
NullableAnnotation
.
NotAnnotated
)
);
return
ImmutableArray
.
Create
(
isNullable
?
NullableAnnotationExtensions
.
AnnotatedAttributeValue
:
NullableAnnotationExtensions
.
NotAnnotatedAttributeValue
);
}
internal
static
ImmutableArray
<
ImmutableArray
<
byte
>>
GetExtraAnnotations
(
string
key
)
...
...
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs
浏览文件 @
90590524
...
...
@@ -296,11 +296,11 @@ public override bool HasReferenceTypeConstraint
if
(((
PEModuleSymbol
)
this
.
ContainingModule
).
Module
.
HasNullableAttribute
(
_handle
,
out
byte
transformFlag
,
out
_
))
{
switch
(
(
NullableAnnotation
)
transformFlag
)
switch
(
transformFlag
)
{
case
NullableAnnotation
.
Annotated
:
case
NullableAnnotation
Extensions
.
AnnotatedAttributeValue
:
return
true
;
case
NullableAnnotation
.
NotAnnotated
:
case
NullableAnnotation
Extensions
.
NotAnnotatedAttributeValue
:
return
false
;
}
}
...
...
src/Compilers/CSharp/Portable/Symbols/NullableAnnotation.cs
浏览文件 @
90590524
...
...
@@ -14,15 +14,15 @@ namespace Microsoft.CodeAnalysis.CSharp
internal
enum
NullableAnnotation
:
byte
{
/// <summary>
/// The type is not annotated in a context where the nullable feature is not enabled.
/// Used for interoperation with existing pre-nullable code.
/// Type is not annotated - string, int, T (including the case when T is unconstrained).
/// </summary>
Oblivious
,
NotAnnotated
,
/// <summary>
/// Type is not annotated - string, int, T (including the case when T is unconstrained).
/// The type is not annotated in a context where the nullable feature is not enabled.
/// Used for interoperation with existing pre-nullable code.
/// </summary>
NotAnnotated
,
Oblivious
,
/// <summary>
/// Type is annotated with '?' - string?, T? where T : class; and for int?, T? where T : struct.
...
...
src/Compilers/CSharp/Portable/Symbols/NullableAnnotationExtensions.cs
浏览文件 @
90590524
...
...
@@ -18,67 +18,54 @@ internal static class NullableAnnotationExtensions
/// <summary>
/// Join nullable annotations from the set of lower bounds for fixing a type parameter.
/// This uses the covariant merging rules.
/// This uses the covariant merging rules.
(Annotated wins over Oblivious which wins over NotAnnotated)
/// </summary>
public
static
NullableAnnotation
Join
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
{
if
(
a
.
IsAnnotated
()
||
b
.
IsAnnotated
())
return
NullableAnnotation
.
Annotated
;
return
(
a
<
b
)
?
a
:
b
;
}
public
static
NullableAnnotation
Join
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
=>
(
a
<
b
)
?
b
:
a
;
/// <summary>
/// Meet two nullable annotations for computing the nullable annotation of a type parameter from upper bounds.
/// This uses the contravariant merging rules.
/// This uses the contravariant merging rules.
(NotAnnotated wins over Oblivious which wins over Annotated)
/// </summary>
public
static
NullableAnnotation
Meet
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
{
if
(
a
.
IsNotAnnotated
()
||
b
.
IsNotAnnotated
())
return
NullableAnnotation
.
NotAnnotated
;
return
(
a
<
b
)
?
a
:
b
;
}
public
static
NullableAnnotation
Meet
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
=>
(
a
<
b
)
?
a
:
b
;
/// <summary>
///
Check that two nullable annotations are "compatible", which means they could be the same. Return the
///
nullable annotation to be used as a result. This uses the invariant merging rules.
///
Return the nullable annotation to use when two annotations are expected to be "compatible", which means
///
they could be the same. These are the "invariant" merging rules. (NotAnnotated wins over Annotated which wins over Oblivious)
/// </summary>
public
static
NullableAnnotation
EnsureCompatible
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
{
if
(
a
.
IsOblivious
())
return
b
;
if
(
b
.
IsOblivious
())
return
a
;
return
(
a
<
b
)
?
a
:
b
;
}
public
static
NullableAnnotation
EnsureCompatible
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
=>
(
a
,
b
)
switch
{
(
NullableAnnotation
.
Oblivious
,
_
)
=>
b
,
(
_
,
NullableAnnotation
.
Oblivious
)
=>
a
,
_
=>
a
<
b
?
a
:
b
,
};
/// <summary>
/// Merges nullability.
/// </summary>
public
static
NullableAnnotation
MergeNullableAnnotation
(
this
NullableAnnotation
a
,
NullableAnnotation
b
,
VarianceKind
variance
)
{
return
variance
switch
public
static
NullableAnnotation
MergeNullableAnnotation
(
this
NullableAnnotation
a
,
NullableAnnotation
b
,
VarianceKind
variance
)
=>
variance
switch
{
VarianceKind
.
In
=>
a
.
Meet
(
b
),
VarianceKind
.
Out
=>
a
.
Join
(
b
),
VarianceKind
.
None
=>
a
.
EnsureCompatible
(
b
),
_
=>
throw
ExceptionUtilities
.
UnexpectedValue
(
variance
)
};
}
/// <summary>
/// The attribute (metadata) representation of <see cref="NullableAnnotation.NotAnnotated"/>.
/// </summary>
public
const
byte
NotAnnotatedAttributeValue
=
(
byte
)
NullableAnnotation
.
NotAnnotated
;
public
const
byte
NotAnnotatedAttributeValue
=
1
;
/// <summary>
/// The attribute (metadata) representation of <see cref="NullableAnnotation.Annotated"/>.
/// </summary>
public
const
byte
AnnotatedAttributeValue
=
(
byte
)
NullableAnnotation
.
Annotated
;
public
const
byte
AnnotatedAttributeValue
=
2
;
/// <summary>
/// The attribute (metadata) representation of <see cref="NullableAnnotation.Oblivious"/>.
/// </summary>
public
const
byte
ObliviousAttributeValue
=
(
byte
)
NullableAnnotation
.
Oblivious
;
public
const
byte
ObliviousAttributeValue
=
0
;
internal
static
NullabilityInfo
ToNullabilityInfo
(
this
CodeAnalysis
.
NullableAnnotation
annotation
,
TypeSymbol
type
)
{
...
...
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
浏览文件 @
90590524
...
...
@@ -551,15 +551,15 @@ public void AddNullableTransforms(ArrayBuilder<byte> transforms)
if
(
NullableAnnotation
.
IsOblivious
()
||
typeSymbol
.
IsValueType
)
{
flag
=
(
byte
)
NullableAnnotation
.
Oblivious
;
flag
=
NullableAnnotationExtensions
.
ObliviousAttributeValue
;
}
else
if
(
NullableAnnotation
.
IsAnnotated
())
{
flag
=
(
byte
)
NullableAnnotation
.
Annotated
;
flag
=
NullableAnnotationExtensions
.
AnnotatedAttributeValue
;
}
else
{
flag
=
(
byte
)
NullableAnnotation
.
NotAnnotated
;
flag
=
NullableAnnotationExtensions
.
NotAnnotatedAttributeValue
;
}
transforms
.
Add
(
flag
);
...
...
@@ -597,17 +597,17 @@ public bool ApplyNullableTransforms(byte defaultTransformFlag, ImmutableArray<by
result
=
result
.
WithTypeAndModifiers
(
newTypeSymbol
,
result
.
CustomModifiers
);
}
switch
(
(
NullableAnnotation
)
transformFlag
)
switch
(
transformFlag
)
{
case
NullableAnnotation
.
Annotated
:
case
NullableAnnotation
Extensions
.
AnnotatedAttributeValue
:
result
=
result
.
AsNullableReferenceType
();
break
;
case
NullableAnnotation
.
NotAnnotated
:
case
NullableAnnotation
Extensions
.
NotAnnotatedAttributeValue
:
result
=
result
.
AsNotNullableReferenceType
();
break
;
case
NullableAnnotation
.
Oblivious
:
case
NullableAnnotation
Extensions
.
ObliviousAttributeValue
:
if
(
result
.
NullableAnnotation
!=
NullableAnnotation
.
Oblivious
&&
!(
result
.
NullableAnnotation
.
IsAnnotated
()
&&
oldTypeSymbol
.
IsNullableType
()))
// Preserve nullable annotation on Nullable<T>.
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录