Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
42a8f4c0
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,发现更多精彩内容 >>
提交
42a8f4c0
编写于
5月 25, 2017
作者:
O
Omar Tawfik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added tests
上级
56764f13
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
3289 addition
and
486 deletion
+3289
-486
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs
...ers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs
+8
-3
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs
...s/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs
+2
-2
src/Compilers/CSharp/Portable/Symbols/Source/CustomModifierUtils.cs
...ers/CSharp/Portable/Symbols/Source/CustomModifierUtils.cs
+3
-1
src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs
...arp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs
+18
-5
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
...Sharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
...rs/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
+1
-1
src/Compilers/CSharp/Test/Emit/Emit/IsConstModifierTests.cs
src/Compilers/CSharp/Test/Emit/Emit/IsConstModifierTests.cs
+2772
-410
src/Compilers/Core/Portable/MetadataReader/MetadataDecoder.cs
...Compilers/Core/Portable/MetadataReader/MetadataDecoder.cs
+41
-54
src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb
...isualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb
+7
-3
src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/IsConstModifierTests.vb
...t/Symbol/SymbolsTests/Metadata/PE/IsConstModifierTests.vb
+436
-6
未找到文件。
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs
浏览文件 @
42a8f4c0
...
...
@@ -1016,20 +1016,25 @@ internal override DiagnosticInfo GetUseSiteDiagnostic()
}
return
CSDiagnosticInfo
.
IsEmpty
(
result
)
?
InterlockedOperations
.
Initialize
(
ref
_uncommonFields
.
_lazyUseSiteDiagnostic
,
null
,
CSDiagnosticInfo
.
EmptyErrorInfo
)
?
InterlockedOperations
.
Initialize
(
ref
AccessUncommonFields
()
.
_lazyUseSiteDiagnostic
,
null
,
CSDiagnosticInfo
.
EmptyErrorInfo
)
:
result
;
}
private
DiagnosticInfo
InitializeUseSiteDiagnostic
(
DiagnosticInfo
diagnostic
)
{
Debug
.
Assert
(!
CSDiagnosticInfo
.
IsEmpty
(
diagnostic
));
if
(
_packedFlags
.
IsUseSiteDiagnosticPopulated
)
{
return
_uncommonFields
?.
_lazyUseSiteDiagnostic
;
}
if
(
diagnostic
!=
null
)
{
Debug
.
Assert
(!
CSDiagnosticInfo
.
IsEmpty
(
diagnostic
));
diagnostic
=
InterlockedOperations
.
Initialize
(
ref
AccessUncommonFields
().
_lazyUseSiteDiagnostic
,
diagnostic
,
CSDiagnosticInfo
.
EmptyErrorInfo
);
}
_packedFlags
.
SetIsUseSiteDiagnosticPopulated
();
return
_uncommonFields
?.
_lazyUseSiteD
iagnostic
;
return
d
iagnostic
;
}
internal
override
ImmutableArray
<
string
>
GetAppliedConditionalSymbols
()
...
...
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs
浏览文件 @
42a8f4c0
...
...
@@ -68,7 +68,7 @@ private enum Flags : byte
var
propertyParams
=
metadataDecoder
.
GetSignatureForProperty
(
handle
,
out
callingConvention
,
out
propEx
);
Debug
.
Assert
(
propertyParams
.
Length
>
0
);
var
isBad
=
propEx
!=
null
;
var
isBad
=
false
;
var
returnInfo
=
propertyParams
[
0
];
PEPropertySymbol
result
;
...
...
@@ -81,7 +81,7 @@ private enum Flags : byte
result
=
new
PEPropertySymbolWithCustomModifiers
(
moduleSymbol
,
containingType
,
handle
,
getMethod
,
setMethod
,
propertyParams
,
metadataDecoder
,
out
isBad
);
}
if
(
isBad
)
if
(
propEx
!=
null
||
isBad
)
{
result
.
_lazyUseSiteDiagnostic
=
new
CSDiagnosticInfo
(
ErrorCode
.
ERR_BindToBogus
,
result
);
}
...
...
src/Compilers/CSharp/Portable/Symbols/Source/CustomModifierUtils.cs
浏览文件 @
42a8f4c0
...
...
@@ -35,7 +35,9 @@ internal static class CustomModifierUtils
// have already been compared.
MethodSymbol
constructedSourceMethod
=
sourceMethod
.
ConstructIfGeneric
(
destinationMethod
.
TypeArguments
);
customModifiers
=
CustomModifiersTuple
.
Create
(
constructedSourceMethod
.
ReturnTypeCustomModifiers
,
constructedSourceMethod
.
RefCustomModifiers
);
customModifiers
=
CustomModifiersTuple
.
Create
(
constructedSourceMethod
.
ReturnTypeCustomModifiers
,
destinationMethod
.
ReturnsByRef
||
destinationMethod
.
ReturnsByRefReadonly
?
constructedSourceMethod
.
RefCustomModifiers
:
ImmutableArray
<
CustomModifier
>.
Empty
);
parameters
=
CopyParameterCustomModifiers
(
constructedSourceMethod
.
Parameters
,
destinationMethod
.
Parameters
,
alsoCopyParamsModifier
);
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs
浏览文件 @
42a8f4c0
...
...
@@ -231,7 +231,8 @@ internal override LexicalSortKey GetLexicalSortKey()
private
sealed
class
InvokeMethod
:
SourceDelegateMethodSymbol
{
private
readonly
RefKind
refKind
;
private
readonly
RefKind
_refKind
;
private
readonly
ImmutableArray
<
CustomModifier
>
_refCustomModifiers
;
internal
InvokeMethod
(
SourceMemberContainerTypeSymbol
delegateType
,
...
...
@@ -242,14 +243,14 @@ private sealed class InvokeMethod : SourceDelegateMethodSymbol
DiagnosticBag
diagnostics
)
:
base
(
delegateType
,
returnType
,
syntax
,
MethodKind
.
DelegateInvoke
,
DeclarationModifiers
.
Virtual
|
DeclarationModifiers
.
Public
)
{
this
.
refKind
=
refKind
;
this
.
_
refKind
=
refKind
;
SyntaxToken
arglistToken
;
var
parameters
=
ParameterHelpers
.
MakeParameters
(
binder
,
this
,
syntax
.
ParameterList
,
out
arglistToken
,
allowRefOrOut
:
true
,
allowThis
:
false
,
addIsConstModifier
:
fals
e
,
addIsConstModifier
:
tru
e
,
diagnostics
:
diagnostics
);
if
(
arglistToken
.
Kind
()
==
SyntaxKind
.
ArgListKeyword
)
...
...
@@ -260,6 +261,16 @@ private sealed class InvokeMethod : SourceDelegateMethodSymbol
diagnostics
.
Add
(
ErrorCode
.
ERR_IllegalVarArgs
,
new
SourceLocation
(
arglistToken
));
}
if
(
_refKind
==
RefKind
.
RefReadOnly
)
{
var
isConstType
=
binder
.
GetWellKnownType
(
WellKnownType
.
System_Runtime_CompilerServices_IsConst
,
diagnostics
,
syntax
.
ReturnType
);
_refCustomModifiers
=
ImmutableArray
.
Create
(
CSharpCustomModifier
.
CreateRequired
(
isConstType
));
}
else
{
_refCustomModifiers
=
ImmutableArray
<
CustomModifier
>.
Empty
;
}
InitializeParameters
(
parameters
);
}
...
...
@@ -270,7 +281,7 @@ public override string Name
internal
override
RefKind
RefKind
{
get
{
return
refKind
;
}
get
{
return
_
refKind
;
}
}
internal
override
LexicalSortKey
GetLexicalSortKey
()
...
...
@@ -288,7 +299,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions,
{
base
.
AfterAddingTypeMembersChecks
(
conversions
,
diagnostics
);
if
(
refKind
==
RefKind
.
RefReadOnly
)
if
(
_
refKind
==
RefKind
.
RefReadOnly
)
{
var
syntax
=
(
DelegateDeclarationSyntax
)
SyntaxRef
.
GetSyntax
();
DeclaringCompilation
.
EnsureIsReadOnlyAttributeExists
(
diagnostics
,
syntax
.
ReturnType
.
GetLocation
(),
modifyCompilationForRefReadOnly
:
true
);
...
...
@@ -296,6 +307,8 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions,
ParameterHelpers
.
EnsureIsReadOnlyAttributeExists
(
Parameters
,
diagnostics
,
modifyCompilationForRefReadOnly
:
true
);
}
public
override
ImmutableArray
<
CustomModifier
>
RefCustomModifiers
=>
_refCustomModifiers
;
}
private
sealed
class
BeginInvokeMethod
:
SourceDelegateMethodSymbol
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
浏览文件 @
42a8f4c0
...
...
@@ -326,7 +326,7 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
out
_lazyParameters
,
alsoCopyParamsModifier
:
true
);
}
}
else
if
(
_refKind
==
RefKind
.
RefReadOnly
&&
(
IsVirtual
||
IsAbstract
)
)
else
if
(
_refKind
==
RefKind
.
RefReadOnly
)
{
var
isConstType
=
withTypeParamsBinder
.
GetWellKnownType
(
WellKnownType
.
System_Runtime_CompilerServices_IsConst
,
diagnostics
,
syntax
.
ReturnType
);
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
浏览文件 @
42a8f4c0
...
...
@@ -273,7 +273,7 @@ internal sealed class SourcePropertySymbol : PropertySymbol, IAttributeTargetSym
_lazyParameters
=
CustomModifierUtils
.
CopyParameterCustomModifiers
(
overriddenOrImplementedProperty
.
Parameters
,
_lazyParameters
,
alsoCopyParamsModifier
:
isOverride
);
}
}
else
if
(
_refKind
==
RefKind
.
RefReadOnly
&&
(
IsVirtual
||
IsAbstract
)
)
else
if
(
_refKind
==
RefKind
.
RefReadOnly
)
{
var
isConstType
=
bodyBinder
.
GetWellKnownType
(
WellKnownType
.
System_Runtime_CompilerServices_IsConst
,
diagnostics
,
syntax
.
Type
);
...
...
src/Compilers/CSharp/Test/Emit/Emit/IsConstModifierTests.cs
浏览文件 @
42a8f4c0
此差异已折叠。
点击以展开。
src/Compilers/Core/Portable/MetadataReader/MetadataDecoder.cs
浏览文件 @
42a8f4c0
...
...
@@ -202,7 +202,7 @@ private TypeSymbol DecodeTypeOrThrow(ref BlobReader ppSig, SignatureTypeCode typ
int
countOfSizes
;
int
countOfLowerBounds
;
modifiers
=
DecodeModifiersOrThrow
(
ref
ppSig
,
out
typeCode
);
modifiers
=
DecodeModifiersOrThrow
(
ref
ppSig
,
AllowedRequiredModifierType
.
None
,
out
typeCode
,
out
_
);
typeSymbol
=
DecodeTypeOrThrow
(
ref
ppSig
,
typeCode
,
out
refersToNoPiaLocalType
);
if
(!
ppSig
.
TryReadCompressedInteger
(
out
countOfDimensions
)
||
!
ppSig
.
TryReadCompressedInteger
(
out
countOfSizes
))
...
...
@@ -285,13 +285,13 @@ private TypeSymbol DecodeTypeOrThrow(ref BlobReader ppSig, SignatureTypeCode typ
break
;
case
SignatureTypeCode
.
SZArray
:
modifiers
=
DecodeModifiersOrThrow
(
ref
ppSig
,
out
typeCode
);
modifiers
=
DecodeModifiersOrThrow
(
ref
ppSig
,
AllowedRequiredModifierType
.
None
,
out
typeCode
,
out
_
);
typeSymbol
=
DecodeTypeOrThrow
(
ref
ppSig
,
typeCode
,
out
refersToNoPiaLocalType
);
typeSymbol
=
GetSZArrayTypeSymbol
(
typeSymbol
,
modifiers
);
break
;
case
SignatureTypeCode
.
Pointer
:
modifiers
=
DecodeModifiersOrThrow
(
ref
ppSig
,
out
typeCode
);
modifiers
=
DecodeModifiersOrThrow
(
ref
ppSig
,
AllowedRequiredModifierType
.
None
,
out
typeCode
,
out
_
);
typeSymbol
=
DecodeTypeOrThrow
(
ref
ppSig
,
typeCode
,
out
refersToNoPiaLocalType
);
typeSymbol
=
MakePointerTypeSymbol
(
typeSymbol
,
modifiers
);
break
;
...
...
@@ -350,7 +350,7 @@ private TypeSymbol DecodeGenericTypeInstanceOrThrow(ref BlobReader ppSig, out bo
{
bool
argumentRefersToNoPia
;
SignatureTypeCode
typeCode
;
ImmutableArray
<
ModifierInfo
<
TypeSymbol
>>
modifiers
=
DecodeModifiersOrThrow
(
ref
ppSig
,
out
typeCode
);
ImmutableArray
<
ModifierInfo
<
TypeSymbol
>>
modifiers
=
DecodeModifiersOrThrow
(
ref
ppSig
,
AllowedRequiredModifierType
.
None
,
out
typeCode
,
out
_
);
argumentsBuilder
.
Add
(
KeyValuePair
.
Create
(
DecodeTypeOrThrow
(
ref
ppSig
,
typeCode
,
out
argumentRefersToNoPia
),
modifiers
));
argumentRefersToNoPiaLocalTypeBuilder
.
Add
(
argumentRefersToNoPia
);
}
...
...
@@ -670,52 +670,18 @@ private TypeSymbol GetTypeOfTypeDef(TypeDefinitionHandle typeDef, out bool isNoP
}
}
/// <exception cref="UnsupportedSignatureContent">If the encoded type is invalid.</exception>
/// <exception cref="BadImageFormatException">An exception from metadata reader.</exception>
private
ImmutableArray
<
ModifierInfo
<
TypeSymbol
>>
DecodeModifiersOrThrow
(
ref
BlobReader
signatureReader
,
out
SignatureTypeCode
typeCode
)
{
ArrayBuilder
<
ModifierInfo
<
TypeSymbol
>>
modifiers
=
null
;
for
(;;)
{
typeCode
=
signatureReader
.
ReadSignatureTypeCode
();
if
(
typeCode
==
SignatureTypeCode
.
RequiredModifier
)
{
throw
new
UnsupportedSignatureContent
();
}
if
(
typeCode
==
SignatureTypeCode
.
OptionalModifier
)
{
ModifierInfo
<
TypeSymbol
>
modifier
=
new
ModifierInfo
<
TypeSymbol
>(
true
,
DecodeModifierTypeOrThrow
(
ref
signatureReader
));
if
(
modifiers
==
null
)
{
modifiers
=
ArrayBuilder
<
ModifierInfo
<
TypeSymbol
>>.
GetInstance
();
}
modifiers
.
Add
(
modifier
);
continue
;
}
break
;
}
return
modifiers
?.
ToImmutableAndFree
()
??
default
(
ImmutableArray
<
ModifierInfo
<
TypeSymbol
>>);
}
/// <exception cref="UnsupportedSignatureContent">If the encoded type is invalid.</exception>
/// <exception cref="BadImageFormatException">An exception from metadata reader.</exception>
private
ImmutableArray
<
ModifierInfo
<
TypeSymbol
>>
DecodeModifiersOrThrow
(
ref
BlobReader
signatureReader
,
AllowedRequiredModifierType
allowedRequiredModifierType
,
out
SignatureTypeCode
typeCode
,
Func
<
TypeSymbol
,
bool
>
acceptRequiredModifier
,
out
bool
requiredModifierFound
)
{
requiredModifierFound
=
false
;
ArrayBuilder
<
ModifierInfo
<
TypeSymbol
>>
modifiers
=
null
;
for
(;
;
)
for
(;
;
)
{
typeCode
=
signatureReader
.
ReadSignatureTypeCode
();
bool
isOptional
;
...
...
@@ -735,10 +701,21 @@ private ImmutableArray<ModifierInfo<TypeSymbol>> DecodeModifiersOrThrow(ref Blob
TypeSymbol
type
=
DecodeModifierTypeOrThrow
(
ref
signatureReader
);
// if it is a required modifier, make sure the compiler supports this modifier type
if
(!
isOptional
)
{
if
(
acceptRequiredModifier
(
type
))
var
isAllowed
=
false
;
switch
(
allowedRequiredModifierType
)
{
case
AllowedRequiredModifierType
.
System_Runtime_CompilerServices_IsConst
:
isAllowed
=
IsAcceptedIsConstModifierType
(
type
);
break
;
case
AllowedRequiredModifierType
.
System_Runtime_CompilerServices_Volatile
:
isAllowed
=
IsAcceptedVolatileModifierType
(
type
);
break
;
}
if
(
isAllowed
)
{
requiredModifierFound
=
true
;
}
...
...
@@ -903,7 +880,7 @@ internal LocalInfo<TypeSymbol> DecodeLocalVariableOrThrow(ref BlobReader signatu
{
SignatureTypeCode
typeCode
;
var
customModifiers
=
DecodeModifiersOrThrow
(
ref
signatureReader
,
out
typeCode
);
var
customModifiers
=
DecodeModifiersOrThrow
(
ref
signatureReader
,
AllowedRequiredModifierType
.
None
,
out
typeCode
,
out
_
);
var
constraints
=
LocalSlotConstraints
.
None
;
TypeSymbol
typeSymbol
;
...
...
@@ -944,7 +921,7 @@ internal void DecodeLocalConstantBlobOrThrow(ref BlobReader sigReader, out TypeS
{
SignatureTypeCode
typeCode
;
var
customModifiers
=
DecodeModifiersOrThrow
(
ref
sigReader
,
out
typeCode
);
var
customModifiers
=
DecodeModifiersOrThrow
(
ref
sigReader
,
AllowedRequiredModifierType
.
None
,
out
typeCode
,
out
_
);
if
(
typeCode
==
SignatureTypeCode
.
TypeHandle
)
{
...
...
@@ -1150,16 +1127,17 @@ internal ImmutableArray<LocalInfo<TypeSymbol>> GetLocalInfo(StandaloneSignatureH
/// <exception cref="UnsupportedSignatureContent">If the encoded parameter type is invalid.</exception>
private
void
DecodeParameterOrThrow
(
ref
BlobReader
signatureReader
,
/*out*/
ref
ParamInfo
<
TypeSymbol
>
info
)
{
bool
refersToNoPiaLocalType
;
SignatureTypeCode
typeCode
;
info
.
CustomModifiers
=
DecodeModifiersOrThrow
(
ref
signatureReader
,
out
typeCode
,
IsAcceptedIsConstModifierType
,
out
bool
isConstFound
);
info
.
CustomModifiers
=
DecodeModifiersOrThrow
(
ref
signatureReader
,
AllowedRequiredModifierType
.
System_Runtime_CompilerServices_IsConst
,
out
SignatureTypeCode
typeCode
,
out
bool
isConstFound
);
if
(
typeCode
==
SignatureTypeCode
.
ByReference
)
{
info
.
IsByRef
=
true
;
info
.
RefCustomModifiers
=
info
.
CustomModifiers
;
info
.
CustomModifiers
=
DecodeModifiersOrThrow
(
ref
signatureReader
,
out
typeCode
);
info
.
CustomModifiers
=
DecodeModifiersOrThrow
(
ref
signatureReader
,
AllowedRequiredModifierType
.
None
,
out
typeCode
,
out
_
);
}
else
if
(
isConstFound
)
{
...
...
@@ -1167,7 +1145,7 @@ private void DecodeParameterOrThrow(ref BlobReader signatureReader, /*out*/ ref
throw
new
UnsupportedSignatureContent
();
}
info
.
Type
=
DecodeTypeOrThrow
(
ref
signatureReader
,
typeCode
,
out
refersToNoPiaLocalType
);
info
.
Type
=
DecodeTypeOrThrow
(
ref
signatureReader
,
typeCode
,
out
_
);
}
// MetaImport::DecodeMethodSignature
...
...
@@ -1907,11 +1885,13 @@ protected TypeSymbol DecodeFieldSignature(ref BlobReader signatureReader, out bo
try
{
SignatureTypeCode
typeCode
;
customModifiers
=
DecodeModifiersOrThrow
(
ref
signatureReader
,
out
typeCode
,
IsAcceptedVolatileModifierType
,
out
isVolatile
);
customModifiers
=
DecodeModifiersOrThrow
(
ref
signatureReader
,
AllowedRequiredModifierType
.
System_Runtime_CompilerServices_Volatile
,
out
typeCode
,
out
isVolatile
);
// get the type
bool
refersToNoPiaLocalType
;
return
DecodeTypeOrThrow
(
ref
signatureReader
,
typeCode
,
out
refersToNoPiaLocalType
);
return
DecodeTypeOrThrow
(
ref
signatureReader
,
typeCode
,
out
_
);
}
catch
(
UnsupportedSignatureContent
)
{
...
...
@@ -2426,5 +2406,12 @@ internal bool DoesSignatureMatchEvent(TypeSymbol eventType, ParamInfo<TypeSymbol
var
methodParam
=
methodParams
[
1
];
return
!
methodParam
.
IsByRef
&&
methodParam
.
Type
.
Equals
(
eventType
);
}
private
enum
AllowedRequiredModifierType
{
None
,
System_Runtime_CompilerServices_Volatile
,
System_Runtime_CompilerServices_IsConst
,
}
}
}
src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb
浏览文件 @
42a8f4c0
...
...
@@ -1094,18 +1094,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
End
If
Return
If
(
result
Is
ErrorFactory
.
EmptyErrorInfo
,
InterlockedOperations
.
Initialize
(
_uncommonFields
.
_lazyUseSiteErrorInfo
,
Nothing
,
ErrorFactory
.
EmptyErrorInfo
),
InterlockedOperations
.
Initialize
(
AccessUncommonFields
()
.
_lazyUseSiteErrorInfo
,
Nothing
,
ErrorFactory
.
EmptyErrorInfo
),
result
)
End
Function
Private
Function
InitializeUseSiteErrorInfo
(
errorInfo
As
DiagnosticInfo
)
As
DiagnosticInfo
Debug
.
Assert
(
errorInfo
IsNot
ErrorFactory
.
EmptyErrorInfo
)
If
_packedFlags
.
IsUseSiteDiagnosticPopulated
Then
Return
_uncommonFields
?
.
_lazyUseSiteErrorInfo
End
If
If
errorInfo
IsNot
Nothing
Then
Debug
.
Assert
(
errorInfo
IsNot
ErrorFactory
.
EmptyErrorInfo
)
errorInfo
=
InterlockedOperations
.
Initialize
(
AccessUncommonFields
().
_lazyUseSiteErrorInfo
,
errorInfo
,
ErrorFactory
.
EmptyErrorInfo
)
End
If
_packedFlags
.
SetIsUseSiteDiagnosticPopulated
()
Return
_uncommonFields
?
.
_lazyUseSiteE
rrorInfo
Return
e
rrorInfo
End
Function
Friend
Overrides
ReadOnly
Property
ObsoleteAttributeData
As
ObsoleteAttributeData
...
...
src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/IsConstModifierTests.vb
浏览文件 @
42a8f4c0
...
...
@@ -9,7 +9,33 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Symbols.Metadata
Inherits
BasicTestBase
<
Fact
>
Public
Sub
NonVirtualReadOnlySignaturesAreRead
()
Public
Sub
ReadOnlySignaturesAreRead_Methods_Parameters_Static
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
public static void M(ref readonly int x)
{
System.Console.WriteLine(x);
}
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
()
Dim
x
=
5
TestRef
.
M
(
x
)
End
Sub
End
Class
</
file
>
</
compilation
>
CompileAndVerify
(
source
,
additionalRefs
:
=
{
reference
},
expectedOutput
:
=
"5"
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreRead_Methods_Parameters_NoModifiers
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
...
...
@@ -35,6 +61,61 @@ End Class
CompileAndVerify
(
source
,
additionalRefs
:
=
{
reference
},
expectedOutput
:
=
"5"
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreRead_Indexers_Parameters_NoModifiers
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
public int this[ref readonly int p]
{
set
{
System.Console.WriteLine(p);
}
}
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
()
Dim
x
=
5
Dim
obj
=
New
TestRef
()
obj
(
x
)
=
0
End
Sub
End
Class
</
file
>
</
compilation
>
CompileAndVerify
(
source
,
additionalRefs
:
=
{
reference
},
expectedOutput
:
=
"5"
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreRead_Operators_Constructors
()
Dim
reference
=
CreateCSharpCompilation
(
"
public struct TestRef
{
public TestRef(ref readonly int value)
{
System.Console.WriteLine(value);
}
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
()
Dim
obj1
=
New
TestRef
(
4
)
End
Sub
End
Class
</
file
>
</
compilation
>
CompileAndVerify
(
source
,
additionalRefs
:
=
{
reference
},
expectedOutput
:
=
"4"
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Methods_Parameters_Virtual
()
Dim
reference
=
CreateCSharpCompilation
(
"
...
...
@@ -68,6 +149,35 @@ BC30657: 'M' has a return type that is not supported or parameter types that are
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Methods_Parameters_Abstract
()
Dim
reference
=
CreateCSharpCompilation
(
"
public abstract class TestRef
{
public abstract void M(ref readonly int x);
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
(
obj
As
TestRef
)
Dim
x
=
5
obj
.
M
(
x
)
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30657
:
'M' has a return type that is not supported or parameter types that are not supported.
obj
.
M
(
x
)
~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Methods_ReturnTypes_Virtual
()
Dim
reference
=
CreateCSharpCompilation
(
"
...
...
@@ -101,6 +211,99 @@ BC30657: 'M' has a return type that is not supported or parameter types that are
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Methods_ReturnTypes_Abstract
()
Dim
reference
=
CreateCSharpCompilation
(
"
public abstract class TestRef
{
public abstract ref readonly int M();
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
(
obj
As
TestRef
)
obj
.
M
()
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30657
:
'M' has a return type that is not supported or parameter types that are not supported.
obj
.
M
()
~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Methods_ReturnTypes_Static
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
private static int value = 0;
public static ref readonly int M()
{
return ref value;
}
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
()
TestRef
.
M
()
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30657
:
'M' has a return type that is not supported or parameter types that are not supported.
TestRef
.
M
()
~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Methods_ReturnTypes_NoModifiers
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
private int value = 0;
public ref readonly int M()
{
return ref value;
}
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
()
Dim
obj
=
New
TestRef
()
obj
.
M
()
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30657
:
'M' has a return type that is not supported or parameter types that are not supported.
obj
.
M
()
~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Properties_Virtual
()
Dim
reference
=
CreateCSharpCompilation
(
"
...
...
@@ -131,6 +334,152 @@ BC30643: Property 'P' is of an unsupported type.
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Properties_Static
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
private static int value = 0;
public static ref readonly int P => ref value;
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
()
Dim
value
=
TestRef
.
P
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30643
:
Property
'P' is of an unsupported type.
Dim
value
=
TestRef
.
P
~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Properties_NoModifiers
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
private int value = 0;
public ref readonly int P => ref value;
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
()
Dim
obj
=
New
TestRef
()
Dim
value
=
obj
.
P
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30643
:
Property
'P' is of an unsupported type.
Dim
value
=
obj
.
P
~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Properties_Abstract
()
Dim
reference
=
CreateCSharpCompilation
(
"
public abstract class TestRef
{
public abstract ref readonly int P { get; }
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
(
obj
As
TestRef
)
Dim
value
=
obj
.
P
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30643
:
Property
'P' is of an unsupported type.
Dim
value
=
obj
.
P
~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Indexers_Parameters_Virtual
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
public virtual int this[ref readonly int p] => 0;
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
()
Dim
p
=
0
Dim
obj
=
New
TestRef
()
Dim
value
=
obj
(
p
)
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30643
:
Property
'TestRef.Item(p As )' is of an unsupported type.
Dim
value
=
obj
(
p
)
~~~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Indexers_Parameters_Abstract
()
Dim
reference
=
CreateCSharpCompilation
(
"
public abstract class TestRef
{
public abstract int this[ref readonly int p] { set; }
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
(
obj
As
TestRef
)
Dim
p
=
0
Dim
value
=
obj
(
p
)
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30643
:
Property
'TestRef.Item(p As )' is of an unsupported type.
Dim
value
=
obj
(
p
)
~~~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Indexers_ReturnTypes_Virtual
()
Dim
reference
=
CreateCSharpCompilation
(
"
...
...
@@ -162,11 +511,40 @@ BC30643: Property 'TestRef.Item(p As )' is of an unsupported type.
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Indexers_Parameters_Virtual
()
Public
Sub
ReadOnlySignaturesAreNotSupported_Indexers_ReturnTypes_Abstract
()
Dim
reference
=
CreateCSharpCompilation
(
"
public abstract class TestRef
{
public abstract ref readonly int this[int p] { get; }
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
(
obj
As
TestRef
)
Dim
value
=
obj
(
0
)
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30643
:
Property
'TestRef.Item(p As )' is of an unsupported type.
Dim
value
=
obj
(
0
)
~~~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
ReadOnlySignaturesAreNotSupported_Indexers_ReturnTypes_NoModifiers
()
Dim
reference
=
CreateCSharpCompilation
(
"
public class TestRef
{
public virtual int this[ref readonly int p] => 0;
private int value = 0;
public ref readonly int this[int p] => ref value;
}"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
...
...
@@ -174,9 +552,8 @@ public class TestRef
<
file
>
Class
Test
Shared
Sub
Main
()
Dim
p
=
0
Dim
obj
=
New
TestRef
()
Dim
value
=
obj
(
p
)
Dim
value
=
obj
(
0
)
End
Sub
End
Class
</
file
>
...
...
@@ -186,10 +563,63 @@ End Class
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30643
:
Property
'TestRef.Item(p As )' is of an unsupported type.
Dim
value
=
obj
(
p
)
Dim
value
=
obj
(
0
)
~~~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
UsingLambdasOfRefReadOnlyDelegatesIsNotSupported_Parameters
()
Dim
reference
=
CreateCSharpCompilation
(
"
public delegate void D(ref readonly int p);
"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
(
lambda
As
D
)
Dim
x
=
0
lambda
(
x
)
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30657
:
'D' has a return type that is not supported or parameter types that are not supported.
lambda
(
x
)
~~~~~~
</
expected
>
)
End
Sub
<
Fact
>
Public
Sub
UsingLambdasOfRefReadOnlyDelegatesIsNotSupported_ReturnTypes
()
Dim
reference
=
CreateCSharpCompilation
(
"
public delegate ref readonly int D();
"
,
parseOptions
:
=
New
CSharpParseOptions
(
CSharp
.
LanguageVersion
.
Latest
)).
EmitToImageReference
()
Dim
source
=
<
compilation
>
<
file
>
Class
Test
Shared
Sub
Main
(
lambda
As
D
)
Dim
x
=
lambda
()
End
Sub
End
Class
</
file
>
</
compilation
>
Dim
compilation
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
reference
})
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30657
:
'D' has a return type that is not supported or parameter types that are not supported.
Dim
x
=
lambda
()
~~~~~~
</
expected
>
)
End
Sub
End
Class
End
Namespace
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录