Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
abe0db95
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
abe0db95
编写于
12月 04, 2020
作者:
J
Julien Couvreur
提交者:
GitHub
12月 04, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix nullability check in override/implementation (#49723)
上级
08a2543b
变更
17
展开全部
隐藏空白更改
内联
并排
Showing
17 changed file
with
870 addition
and
107 deletion
+870
-107
src/Compilers/CSharp/Portable/Binder/Binder_Crefs.cs
src/Compilers/CSharp/Portable/Binder/Binder_Crefs.cs
+1
-1
src/Compilers/CSharp/Portable/Emitter/EditAndContinue/CSharpSymbolMatcher.cs
...p/Portable/Emitter/EditAndContinue/CSharpSymbolMatcher.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/NullableAnnotation.cs
src/Compilers/CSharp/Portable/Symbols/NullableAnnotation.cs
+11
-0
src/Compilers/CSharp/Portable/Symbols/NullableAnnotationExtensions.cs
...s/CSharp/Portable/Symbols/NullableAnnotationExtensions.cs
+38
-12
src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingSymbolTranslator.cs
...rtable/Symbols/Retargeting/RetargetingSymbolTranslator.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/Source/IndexedTypeParameterSymbol.cs
...arp/Portable/Symbols/Source/IndexedTypeParameterSymbol.cs
+18
-1
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol_ImplementationChecks.cs
...ource/SourceMemberContainerSymbol_ImplementationChecks.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
...arp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/TypeMap.cs
src/Compilers/CSharp/Portable/Symbols/TypeMap.cs
+7
-2
src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs
src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs
+7
-5
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
+8
-9
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
...rp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+763
-60
src/Compilers/CSharp/Test/Symbol/Symbols/Source/IndexedTypeParameterTests.cs
...p/Test/Symbol/Symbols/Source/IndexedTypeParameterTests.cs
+4
-4
src/Compilers/Core/Portable/Symbols/ISymbol.cs
src/Compilers/Core/Portable/Symbols/ISymbol.cs
+1
-1
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.ExpressionSyntaxGeneratorVisitor.cs
...ITypeSymbolExtensions.ExpressionSyntaxGeneratorVisitor.cs
+4
-4
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs
...sions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs
+2
-2
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.cs
...ions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.cs
+2
-2
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Crefs.cs
浏览文件 @
abe0db95
...
...
@@ -750,7 +750,7 @@ private static ImmutableArray<Symbol> PerformCrefOverloadResolution(ArrayBuilder
// CONSIDER: we might want to reuse this method symbol (as long as the MethodKind and Vararg-ness match).
signatureMember
=
new
SignatureOnlyMethodSymbol
(
methodKind
:
candidateMethodKind
,
typeParameters
:
IndexedTypeParameterSymbol
.
Take
(
signatureMemberArity
),
typeParameters
:
IndexedTypeParameterSymbol
.
Take
Symbols
(
signatureMemberArity
),
parameters
:
parameterSymbols
,
// This specific comparer only looks for varargs.
callingConvention
:
candidateMethodIsVararg
?
Microsoft
.
Cci
.
CallingConvention
.
ExtraArguments
:
Microsoft
.
Cci
.
CallingConvention
.
HasThis
,
...
...
src/Compilers/CSharp/Portable/Emitter/EditAndContinue/CSharpSymbolMatcher.cs
浏览文件 @
abe0db95
...
...
@@ -743,7 +743,7 @@ private static MethodSymbol SubstituteTypeParameters(MethodSymbol method)
return
method
;
}
return
method
.
Construct
(
IndexedTypeParameterSymbol
.
Take
(
n
)
.
Cast
<
TypeParameterSymbol
,
TypeSymbol
>()
);
return
method
.
Construct
(
IndexedTypeParameterSymbol
.
Take
(
n
));
}
private
bool
AreNamedTypesEqual
(
NamedTypeSymbol
type
,
NamedTypeSymbol
other
)
...
...
src/Compilers/CSharp/Portable/Symbols/NullableAnnotation.cs
浏览文件 @
abe0db95
...
...
@@ -32,5 +32,16 @@ internal enum NullableAnnotation : byte
/// Type is annotated with '?' - string?, T?.
/// </summary>
Annotated
,
/// <summary>
/// Used for indexed type parameters and used locally in override/implementation checks.
/// When substituting a type parameter with Ignored annotation into some original type parameter
/// with some other annotation, the result is the annotation from the original symbol.
///
/// T annotated + (T -> U ignored) = U annotated
/// T oblivious + (T -> U ignored) = U oblivious
/// T not-annotated + (T -> U ignored) = U not-annotated
/// </summary>
Ignored
,
}
}
src/Compilers/CSharp/Portable/Symbols/NullableAnnotationExtensions.cs
浏览文件 @
abe0db95
...
...
@@ -5,6 +5,7 @@
#
nullable
disable
using
System.Collections.Immutable
;
using
System.Diagnostics
;
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Roslyn.Utilities
;
...
...
@@ -25,37 +26,55 @@ internal static class NullableAnnotationExtensions
/// Join nullable annotations from the set of lower bounds for fixing a type parameter.
/// This uses the covariant merging rules. (Annotated wins over Oblivious which wins over NotAnnotated)
/// </summary>
public
static
NullableAnnotation
Join
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
=>
(
a
<
b
)
?
b
:
a
;
public
static
NullableAnnotation
Join
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
{
Debug
.
Assert
(
a
!=
NullableAnnotation
.
Ignored
);
Debug
.
Assert
(
b
!=
NullableAnnotation
.
Ignored
);
return
(
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. (NotAnnotated wins over Oblivious which wins over Annotated)
/// </summary>
public
static
NullableAnnotation
Meet
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
=>
(
a
<
b
)
?
a
:
b
;
public
static
NullableAnnotation
Meet
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
{
Debug
.
Assert
(
a
!=
NullableAnnotation
.
Ignored
);
Debug
.
Assert
(
b
!=
NullableAnnotation
.
Ignored
);
return
(
a
<
b
)
?
a
:
b
;
}
/// <summary>
/// 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
)
=>
(
a
,
b
)
switch
public
static
NullableAnnotation
EnsureCompatible
(
this
NullableAnnotation
a
,
NullableAnnotation
b
)
{
Debug
.
Assert
(
a
!=
NullableAnnotation
.
Ignored
);
Debug
.
Assert
(
b
!=
NullableAnnotation
.
Ignored
);
return
(
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
)
=>
variance
switch
public
static
NullableAnnotation
MergeNullableAnnotation
(
this
NullableAnnotation
a
,
NullableAnnotation
b
,
VarianceKind
variance
)
{
Debug
.
Assert
(
a
!=
NullableAnnotation
.
Ignored
);
Debug
.
Assert
(
b
!=
NullableAnnotation
.
Ignored
);
return
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"/>.
...
...
@@ -105,18 +124,25 @@ internal static ImmutableArray<ITypeSymbol> GetPublicSymbols(this ImmutableArray
internal
static
ImmutableArray
<
CodeAnalysis
.
NullableAnnotation
>
ToPublicAnnotations
(
this
ImmutableArray
<
TypeWithAnnotations
>
types
)
=>
types
.
SelectAsArray
(
t
=>
t
.
ToPublicAnnotation
());
internal
static
CodeAnalysis
.
NullableAnnotation
ToPublicAnnotation
(
TypeSymbol
type
,
NullableAnnotation
annotation
)
=>
annotation
switch
internal
static
CodeAnalysis
.
NullableAnnotation
ToPublicAnnotation
(
TypeSymbol
type
,
NullableAnnotation
annotation
)
{
Debug
.
Assert
(
annotation
!=
NullableAnnotation
.
Ignored
);
return
annotation
switch
{
CSharp
.
NullableAnnotation
.
Annotated
=>
CodeAnalysis
.
NullableAnnotation
.
Annotated
,
CSharp
.
NullableAnnotation
.
NotAnnotated
=>
CodeAnalysis
.
NullableAnnotation
.
NotAnnotated
,
NullableAnnotation
.
Annotated
=>
CodeAnalysis
.
NullableAnnotation
.
Annotated
,
NullableAnnotation
.
NotAnnotated
=>
CodeAnalysis
.
NullableAnnotation
.
NotAnnotated
,
// A value type may be oblivious or not annotated depending on whether the type reference
// is from source or metadata. (Binding using the #nullable context only when setting the annotation
// to avoid checking IsValueType early.) The annotation is normalized here in the public API.
CSharp
.
NullableAnnotation
.
Oblivious
when
type
.
IsValueType
=>
CodeAnalysis
.
NullableAnnotation
.
NotAnnotated
,
CSharp
.
NullableAnnotation
.
Oblivious
=>
CodeAnalysis
.
NullableAnnotation
.
None
,
NullableAnnotation
.
Oblivious
when
type
.
IsValueType
=>
CodeAnalysis
.
NullableAnnotation
.
NotAnnotated
,
NullableAnnotation
.
Oblivious
=>
CodeAnalysis
.
NullableAnnotation
.
None
,
NullableAnnotation
.
Ignored
=>
CodeAnalysis
.
NullableAnnotation
.
None
,
_
=>
throw
ExceptionUtilities
.
UnexpectedValue
(
annotation
)
};
}
internal
static
CSharp
.
NullableAnnotation
ToInternalAnnotation
(
this
CodeAnalysis
.
NullableAnnotation
annotation
)
=>
annotation
switch
...
...
src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingSymbolTranslator.cs
浏览文件 @
abe0db95
...
...
@@ -989,7 +989,7 @@ IEqualityComparer<MethodSymbol> retargetedMethodComparer
retargetedType
,
method
.
MethodKind
,
method
.
CallingConvention
,
IndexedTypeParameterSymbol
.
Take
(
method
.
Arity
),
IndexedTypeParameterSymbol
.
Take
Symbols
(
method
.
Arity
),
targetParamsBuilder
.
ToImmutableAndFree
(),
method
.
RefKind
,
method
.
IsInitOnly
,
...
...
src/Compilers/CSharp/Portable/Symbols/Source/IndexedTypeParameterSymbol.cs
浏览文件 @
abe0db95
...
...
@@ -82,7 +82,7 @@ private static void GrowPool(int count)
/// </summary>
/// <param name="count"></param>
/// <returns></returns>
internal
static
ImmutableArray
<
TypeParameterSymbol
>
Take
(
int
count
)
internal
static
ImmutableArray
<
TypeParameterSymbol
>
Take
Symbols
(
int
count
)
{
if
(
count
>
s_parameterPool
.
Length
)
{
...
...
@@ -99,6 +99,23 @@ internal static ImmutableArray<TypeParameterSymbol> Take(int count)
return
builder
.
ToImmutableAndFree
();
}
internal
static
ImmutableArray
<
TypeWithAnnotations
>
Take
(
int
count
)
{
if
(
count
>
s_parameterPool
.
Length
)
{
GrowPool
(
count
);
}
var
builder
=
ArrayBuilder
<
TypeWithAnnotations
>.
GetInstance
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
builder
.
Add
(
TypeWithAnnotations
.
Create
(
GetTypeParameter
(
i
),
NullableAnnotation
.
Ignored
));
}
return
builder
.
ToImmutableAndFree
();
}
public
override
int
Ordinal
{
get
{
return
_index
;
}
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol_ImplementationChecks.cs
浏览文件 @
abe0db95
...
...
@@ -944,7 +944,7 @@ void checkSingleOverriddenMember(Symbol overridingMember, Symbol overriddenMembe
if
(
overridingMethod
.
IsGenericMethod
)
{
overriddenMethod
=
overriddenMethod
.
Construct
(
overridingMethod
.
TypeArgumentsWithAnnotations
);
overriddenMethod
=
overriddenMethod
.
Construct
(
TypeMap
.
TypeParametersAsTypeSymbolsWithIgnoredAnnotations
(
overridingMethod
.
TypeParameters
)
);
}
// Check for mismatched byref returns and return type. Ignore custom modifiers, because this diagnostic is based on the C# semantics.
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
浏览文件 @
abe0db95
...
...
@@ -632,7 +632,7 @@ private static void PartialMethodChecks(SourceOrdinaryMethodSymbol definition, S
{
Debug
.
Assert
(!
ReferenceEquals
(
definition
,
implementation
));
MethodSymbol
constructedDefinition
=
definition
.
ConstructIfGeneric
(
implementation
.
TypeArgumentsWithAnnotations
);
MethodSymbol
constructedDefinition
=
definition
.
ConstructIfGeneric
(
TypeMap
.
TypeParametersAsTypeSymbolsWithIgnoredAnnotations
(
implementation
.
TypeParameters
)
);
bool
returnTypesEqual
=
constructedDefinition
.
ReturnTypeWithAnnotations
.
Equals
(
implementation
.
ReturnTypeWithAnnotations
,
TypeCompareKind
.
AllIgnoreOptions
);
if
(!
returnTypesEqual
&&
!
SourceMemberContainerTypeSymbol
.
IsOrContainsErrorType
(
implementation
.
ReturnType
)
...
...
src/Compilers/CSharp/Portable/Symbols/TypeMap.cs
浏览文件 @
abe0db95
...
...
@@ -20,11 +20,16 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// </summary>
internal
sealed
class
TypeMap
:
AbstractTypeParameterMap
{
public
static
readonly
System
.
Func
<
TypeWithAnnotations
,
TypeSymbol
>
AsTypeSymbol
=
t
=>
t
.
Type
;
public
static
readonly
Func
<
TypeWithAnnotations
,
TypeSymbol
>
AsTypeSymbol
=
t
=>
t
.
Type
;
internal
static
ImmutableArray
<
TypeWithAnnotations
>
TypeParametersAsTypeSymbolsWithAnnotations
(
ImmutableArray
<
TypeParameterSymbol
>
typeParameters
)
{
return
typeParameters
.
SelectAsArray
((
tp
)
=>
TypeWithAnnotations
.
Create
(
tp
));
return
typeParameters
.
SelectAsArray
(
static
(
tp
)
=>
TypeWithAnnotations
.
Create
(
tp
));
}
internal
static
ImmutableArray
<
TypeWithAnnotations
>
TypeParametersAsTypeSymbolsWithIgnoredAnnotations
(
ImmutableArray
<
TypeParameterSymbol
>
typeParameters
)
{
return
typeParameters
.
SelectAsArray
(
static
(
tp
)
=>
TypeWithAnnotations
.
Create
(
tp
,
NullableAnnotation
.
Ignored
));
}
internal
static
ImmutableArray
<
TypeSymbol
>
AsTypeSymbols
(
ImmutableArray
<
TypeWithAnnotations
>
typesOpt
)
...
...
src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs
浏览文件 @
abe0db95
...
...
@@ -1690,10 +1690,12 @@ internal static void CheckNullableReferenceTypeMismatchOnImplementingMember(Type
{
if
(
arg
.
isExplicit
)
{
// We use ConstructedFrom symbols here and below to not leak methods with Ignored annotations in type arguments
// into diagnostics
diagnostics
.
Add
(
topLevel
?
ErrorCode
.
WRN_TopLevelNullabilityMismatchInReturnTypeOnExplicitImplementation
:
ErrorCode
.
WRN_NullabilityMismatchInReturnTypeOnExplicitImplementation
,
implementingMethod
.
Locations
[
0
],
new
FormattedSymbol
(
implementedMethod
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
));
implementingMethod
.
Locations
[
0
],
new
FormattedSymbol
(
implementedMethod
.
ConstructedFrom
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
));
}
else
{
...
...
@@ -1702,7 +1704,7 @@ internal static void CheckNullableReferenceTypeMismatchOnImplementingMember(Type
ErrorCode
.
WRN_NullabilityMismatchInReturnTypeOnImplicitImplementation
,
GetImplicitImplementationDiagnosticLocation
(
implementedMethod
,
arg
.
implementingType
,
implementingMethod
),
new
FormattedSymbol
(
implementingMethod
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
),
new
FormattedSymbol
(
implementedMethod
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
));
new
FormattedSymbol
(
implementedMethod
.
ConstructedFrom
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
));
}
};
...
...
@@ -1716,7 +1718,7 @@ internal static void CheckNullableReferenceTypeMismatchOnImplementingMember(Type
ErrorCode
.
WRN_NullabilityMismatchInParameterTypeOnExplicitImplementation
,
implementingMethod
.
Locations
[
0
],
new
FormattedSymbol
(
implementingParameter
,
SymbolDisplayFormat
.
ShortFormat
),
new
FormattedSymbol
(
implementedMethod
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
));
new
FormattedSymbol
(
implementedMethod
.
ConstructedFrom
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
));
}
else
{
...
...
@@ -1726,7 +1728,7 @@ internal static void CheckNullableReferenceTypeMismatchOnImplementingMember(Type
GetImplicitImplementationDiagnosticLocation
(
implementedMethod
,
arg
.
implementingType
,
implementingMethod
),
new
FormattedSymbol
(
implementingParameter
,
SymbolDisplayFormat
.
ShortFormat
),
new
FormattedSymbol
(
implementingMethod
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
),
new
FormattedSymbol
(
implementedMethod
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
));
new
FormattedSymbol
(
implementedMethod
.
ConstructedFrom
,
SymbolDisplayFormat
.
MinimallyQualifiedFormat
));
}
};
...
...
@@ -1770,7 +1772,7 @@ internal static void CheckNullableReferenceTypeMismatchOnImplementingMember(Type
if
(
implementedMethod
.
IsGenericMethod
)
{
implementedMethod
=
implementedMethod
.
Construct
(
implementingMethod
.
TypeArgumentsWithAnnotations
);
implementedMethod
=
implementedMethod
.
Construct
(
TypeMap
.
TypeParametersAsTypeSymbolsWithIgnoredAnnotations
(
implementingMethod
.
TypeParameters
)
);
}
SourceMemberContainerTypeSymbol
.
CheckValidNullableMethodOverride
(
...
...
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
浏览文件 @
abe0db95
...
...
@@ -86,6 +86,7 @@ internal static TypeWithAnnotations Create(TypeSymbol typeSymbol, NullableAnnota
return
default
;
}
Debug
.
Assert
(
nullableAnnotation
!=
NullableAnnotation
.
Ignored
||
typeSymbol
.
IsTypeParameter
());
switch
(
nullableAnnotation
)
{
case
NullableAnnotation
.
Oblivious
:
...
...
@@ -161,11 +162,6 @@ internal bool CanBeAssignedNull
}
}
private
static
bool
IsIndexedTypeParameter
(
TypeSymbol
typeSymbol
)
{
return
typeSymbol
is
IndexedTypeParameterSymbol
;
}
private
static
TypeWithAnnotations
CreateNonLazyType
(
TypeSymbol
typeSymbol
,
NullableAnnotation
nullableAnnotation
,
ImmutableArray
<
CustomModifier
>
customModifiers
)
{
return
new
TypeWithAnnotations
(
typeSymbol
,
nullableAnnotation
,
Extensions
.
Create
(
customModifiers
));
...
...
@@ -429,6 +425,9 @@ public bool IsAtLeastAsVisibleAs(Symbol sym, ref HashSet<DiagnosticInfo> useSite
internal
TypeWithAnnotations
SubstituteTypeCore
(
AbstractTypeMap
typeMap
)
{
// Ignored may only appear on a replacement type and will not survive the substitution (ie. the original annotation wins over Ignored)
Debug
.
Assert
(
NullableAnnotation
!=
NullableAnnotation
.
Ignored
);
var
newCustomModifiers
=
typeMap
.
SubstituteCustomModifiers
(
this
.
CustomModifiers
);
TypeSymbol
typeSymbol
=
this
.
Type
;
var
newTypeWithModifiers
=
typeMap
.
SubstituteType
(
typeSymbol
);
...
...
@@ -437,6 +436,7 @@ internal TypeWithAnnotations SubstituteTypeCore(AbstractTypeMap typeMap)
{
Debug
.
Assert
(
newTypeWithModifiers
.
NullableAnnotation
.
IsOblivious
()
||
(
typeSymbol
.
IsNullableType
()
&&
newTypeWithModifiers
.
NullableAnnotation
.
IsAnnotated
()));
Debug
.
Assert
(
newTypeWithModifiers
.
CustomModifiers
.
IsEmpty
);
Debug
.
Assert
(
NullableAnnotation
!=
NullableAnnotation
.
Ignored
);
if
(
typeSymbol
.
Equals
(
newTypeWithModifiers
.
Type
,
TypeCompareKind
.
ConsiderEverything
)
&&
newCustomModifiers
==
CustomModifiers
)
...
...
@@ -457,7 +457,7 @@ internal TypeWithAnnotations SubstituteTypeCore(AbstractTypeMap typeMap)
{
return
this
;
// substitution had no effect on the type or modifiers
}
else
if
(
Is
((
TypeParameterSymbol
)
typeSymbol
))
else
if
(
Is
((
TypeParameterSymbol
)
typeSymbol
)
&&
newTypeWithModifiers
.
NullableAnnotation
!=
NullableAnnotation
.
Ignored
)
{
return
newTypeWithModifiers
;
}
...
...
@@ -468,14 +468,13 @@ internal TypeWithAnnotations SubstituteTypeCore(AbstractTypeMap typeMap)
}
NullableAnnotation
newAnnotation
;
Debug
.
Assert
(!
IsIndexedTypeParameter
(
newTypeWithModifiers
.
Type
)
||
newTypeWithModifiers
.
NullableAnnotation
.
IsOblivious
());
Debug
.
Assert
(
newTypeWithModifiers
.
Type
is
not
IndexedTypeParameterSymbol
||
newTypeWithModifiers
.
NullableAnnotation
==
NullableAnnotation
.
Ignored
);
if
(
NullableAnnotation
.
IsAnnotated
()
||
newTypeWithModifiers
.
NullableAnnotation
.
IsAnnotated
())
{
newAnnotation
=
NullableAnnotation
.
Annotated
;
}
else
if
(
IsIndexedTypeParameter
(
newTypeWithModifiers
.
Type
)
)
else
if
(
newTypeWithModifiers
.
NullableAnnotation
==
NullableAnnotation
.
Ignored
)
{
newAnnotation
=
NullableAnnotation
;
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
浏览文件 @
abe0db95
此差异已折叠。
点击以展开。
src/Compilers/CSharp/Test/Symbol/Symbols/Source/IndexedTypeParameterTests.cs
浏览文件 @
abe0db95
...
...
@@ -18,10 +18,10 @@ public class IndexedTypeParameterTests
[
Fact
]
public
void
TestTake
()
{
var
zero
=
IndexedTypeParameterSymbol
.
Take
(
0
);
var
zero
=
IndexedTypeParameterSymbol
.
Take
Symbols
(
0
);
Assert
.
Equal
(
0
,
zero
.
Length
);
var
five
=
IndexedTypeParameterSymbol
.
Take
(
5
);
var
five
=
IndexedTypeParameterSymbol
.
Take
Symbols
(
5
);
Assert
.
Equal
(
5
,
five
.
Length
);
Assert
.
Equal
(
five
[
0
],
IndexedTypeParameterSymbol
.
GetTypeParameter
(
0
));
Assert
.
Equal
(
five
[
1
],
IndexedTypeParameterSymbol
.
GetTypeParameter
(
1
));
...
...
@@ -29,14 +29,14 @@ public void TestTake()
Assert
.
Equal
(
five
[
3
],
IndexedTypeParameterSymbol
.
GetTypeParameter
(
3
));
Assert
.
Equal
(
five
[
4
],
IndexedTypeParameterSymbol
.
GetTypeParameter
(
4
));
var
fifty
=
IndexedTypeParameterSymbol
.
Take
(
50
);
var
fifty
=
IndexedTypeParameterSymbol
.
Take
Symbols
(
50
);
Assert
.
Equal
(
50
,
fifty
.
Length
);
// prove they are all unique
var
set
=
new
HashSet
<
TypeParameterSymbol
>(
fifty
);
Assert
.
Equal
(
50
,
set
.
Count
);
var
fiveHundred
=
IndexedTypeParameterSymbol
.
Take
(
500
);
var
fiveHundred
=
IndexedTypeParameterSymbol
.
Take
Symbols
(
500
);
Assert
.
Equal
(
500
,
fiveHundred
.
Length
);
}
}
...
...
src/Compilers/Core/Portable/Symbols/ISymbol.cs
浏览文件 @
abe0db95
...
...
@@ -203,7 +203,7 @@ public interface ISymbol : IEquatable<ISymbol?>
ISymbol
OriginalDefinition
{
get
;
}
void
Accept
(
SymbolVisitor
visitor
);
TResult
Accept
<
TResult
>(
SymbolVisitor
<
TResult
>
visitor
);
TResult
?
Accept
<
TResult
>(
SymbolVisitor
<
TResult
>
visitor
);
/// <summary>
/// Returns the Documentation Comment ID for the symbol, or null if the symbol doesn't
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.ExpressionSyntaxGeneratorVisitor.cs
浏览文件 @
abe0db95
...
...
@@ -19,7 +19,7 @@ private ExpressionSyntaxGeneratorVisitor()
}
public
override
ExpressionSyntax
DefaultVisit
(
ISymbol
symbol
)
=>
symbol
.
Accept
(
TypeSyntaxGeneratorVisitor
.
Create
());
=>
symbol
.
Accept
(
TypeSyntaxGeneratorVisitor
.
Create
())
!
;
private
static
TExpressionSyntax
AddInformationTo
<
TExpressionSyntax
>(
TExpressionSyntax
syntax
,
ISymbol
symbol
)
where
TExpressionSyntax
:
ExpressionSyntax
...
...
@@ -48,7 +48,7 @@ public override ExpressionSyntax VisitNamedType(INamedTypeSymbol symbol)
}
else
{
var
container
=
symbol
.
ContainingType
.
Accept
(
this
);
var
container
=
symbol
.
ContainingType
.
Accept
(
this
)
!
;
return
CreateMemberAccessExpression
(
symbol
,
container
,
simpleNameSyntax
);
}
}
...
...
@@ -66,7 +66,7 @@ public override ExpressionSyntax VisitNamedType(INamedTypeSymbol symbol)
}
else
{
var
container
=
symbol
.
ContainingNamespace
.
Accept
(
this
);
var
container
=
symbol
.
ContainingNamespace
.
Accept
(
this
)
!
;
return
CreateMemberAccessExpression
(
symbol
,
container
,
simpleNameSyntax
);
}
}
...
...
@@ -91,7 +91,7 @@ public override ExpressionSyntax VisitNamespace(INamespaceSymbol symbol)
}
else
{
var
container
=
symbol
.
ContainingNamespace
.
Accept
(
this
);
var
container
=
symbol
.
ContainingNamespace
.
Accept
(
this
)
!
;
return
CreateMemberAccessExpression
(
symbol
,
container
,
syntax
);
}
}
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs
浏览文件 @
abe0db95
...
...
@@ -293,7 +293,7 @@ public override TypeSyntax VisitNamedType(INamedTypeSymbol symbol)
}
else
{
var
container
=
symbol
.
ContainingNamespace
.
Accept
(
this
);
var
container
=
symbol
.
ContainingNamespace
.
Accept
(
this
)
!
;
typeSyntax
=
AddInformationTo
(
SyntaxFactory
.
QualifiedName
(
(
NameSyntax
)
container
,
simpleNameSyntax
),
symbol
);
...
...
@@ -323,7 +323,7 @@ public override TypeSyntax VisitNamespace(INamespaceSymbol symbol)
}
else
{
var
container
=
symbol
.
ContainingNamespace
.
Accept
(
this
);
var
container
=
symbol
.
ContainingNamespace
.
Accept
(
this
)
!
;
return
AddInformationTo
(
SyntaxFactory
.
QualifiedName
(
(
NameSyntax
)
container
,
syntax
),
symbol
);
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.cs
浏览文件 @
abe0db95
...
...
@@ -22,7 +22,7 @@ internal static partial class ITypeSymbolExtensions
public
static
ExpressionSyntax
GenerateExpressionSyntax
(
this
ITypeSymbol
typeSymbol
)
{
return
typeSymbol
.
Accept
(
ExpressionSyntaxGeneratorVisitor
.
Instance
).
WithAdditionalAnnotations
(
Simplifier
.
Annotation
);
return
typeSymbol
.
Accept
(
ExpressionSyntaxGeneratorVisitor
.
Instance
)
!
.
WithAdditionalAnnotations
(
Simplifier
.
Annotation
);
}
public
static
NameSyntax
GenerateNameSyntax
(
...
...
@@ -48,7 +48,7 @@ internal static partial class ITypeSymbolExtensions
return
SyntaxFactory
.
IdentifierName
(
"var"
);
}
var
syntax
=
symbol
.
Accept
(
TypeSyntaxGeneratorVisitor
.
Create
(
nameSyntax
))
var
syntax
=
symbol
.
Accept
(
TypeSyntaxGeneratorVisitor
.
Create
(
nameSyntax
))
!
.
WithAdditionalAnnotations
(
Simplifier
.
Annotation
);
if
(!
allowVar
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录