Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
df875bfc
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,发现更多精彩内容 >>
提交
df875bfc
编写于
5月 04, 2017
作者:
V
vsadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use IsByRefLike attribute
上级
32c82d85
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
330 addition
and
47 deletion
+330
-47
src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversions.cs
...harp/Portable/Binder/Semantics/Conversions/Conversions.cs
+1
-1
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
+2
-0
src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs
...s/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs
+6
-0
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs
.../CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs
+57
-0
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
...rp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
+8
-0
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs
...CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs
+1
-2
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
...s/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
+6
-0
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
...rs/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
+6
-2
src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs
src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs
+2
-22
src/Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
...Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/Wrapped/WrappedNamedTypeSymbol.cs
...CSharp/Portable/Symbols/Wrapped/WrappedNamedTypeSymbol.cs
+5
-0
src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs
...rs/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs
+160
-13
src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs
...pilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs
+3
-1
src/Compilers/CSharp/Test/Syntax/Parsing/RefStructs.cs
src/Compilers/CSharp/Test/Syntax/Parsing/RefStructs.cs
+44
-1
src/Compilers/Core/Portable/MetadataReader/PEModule.cs
src/Compilers/Core/Portable/MetadataReader/PEModule.cs
+5
-0
src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs
.../Core/Portable/Symbols/Attributes/AttributeDescription.cs
+2
-0
src/Compilers/Core/Portable/WellKnownMember.cs
src/Compilers/Core/Portable/WellKnownMember.cs
+2
-0
src/Compilers/Core/Portable/WellKnownMembers.cs
src/Compilers/Core/Portable/WellKnownMembers.cs
+9
-0
src/Compilers/Core/Portable/WellKnownTypes.cs
src/Compilers/Core/Portable/WellKnownTypes.cs
+2
-0
src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb
.../Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb
+8
-4
未找到文件。
src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversions.cs
浏览文件 @
df875bfc
...
...
@@ -320,7 +320,7 @@ private static Conversion ToConversion(OverloadResolutionResult<MethodSymbol> re
//PROTOTYPE(span): generalize to all restricted types or it would be a compat break?
//cannot capture span-like types.
if
(!
method
.
IsStatic
&&
methodGroup
.
Receiver
.
Type
.
Is
SpanLikeType
()
)
if
(!
method
.
IsStatic
&&
methodGroup
.
Receiver
.
Type
.
Is
ByRefLikeType
)
{
return
Conversion
.
NoConversion
;
}
...
...
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
浏览文件 @
df875bfc
...
...
@@ -1444,6 +1444,8 @@ private bool IsPartialType()
Debug
.
Assert
(
this
.
CurrentToken
.
ContextualKind
==
SyntaxKind
.
PartialKeyword
);
switch
(
this
.
PeekToken
(
1
).
Kind
)
{
case
SyntaxKind
.
RefKeyword
:
return
this
.
PeekToken
(
2
).
Kind
==
SyntaxKind
.
StructKeyword
;
case
SyntaxKind
.
StructKeyword
:
case
SyntaxKind
.
ClassKeyword
:
case
SyntaxKind
.
InterfaceKeyword
:
...
...
src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs
浏览文件 @
df875bfc
...
...
@@ -534,6 +534,12 @@ internal SynthesizedAttributeData SynthesizeTupleNamesAttribute(TypeSymbol type)
return
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_CompilerServices_TupleElementNamesAttribute__ctorTransformNames
,
args
);
}
internal
SynthesizedAttributeData
SynthesizeIsByRefLikeAttribute
()
{
// PROTOTYPE(readonlyRefs) it is optional now as it will be generated in the next change
return
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_CompilerServices_IsByRefLikeAttribute__ctor
,
isOptionalUse
:
true
);
}
internal
static
class
TupleNamesEncoder
{
public
static
ImmutableArray
<
string
>
Encode
(
TypeSymbol
type
)
...
...
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs
浏览文件 @
df875bfc
...
...
@@ -129,6 +129,7 @@ private class UncommonProperties
internal
ObsoleteAttributeData
lazyObsoleteAttributeData
=
ObsoleteAttributeData
.
Uninitialized
;
internal
AttributeUsageInfo
lazyAttributeUsageInfo
=
AttributeUsageInfo
.
Null
;
internal
ThreeState
lazyContainsExtensionMethods
;
internal
ThreeState
lazyIsByRefLike
;
internal
string
lazyDefaultMemberName
;
internal
NamedTypeSymbol
lazyComImportCoClassType
=
ErrorTypeSymbol
.
UnknownResultType
;
...
...
@@ -2021,6 +2022,62 @@ internal override bool IsSerializable
get
{
return
(
_flags
&
TypeAttributes
.
Serializable
)
!=
0
;
}
}
internal
override
bool
IsByRefLikeType
{
get
{
var
uncommon
=
GetUncommonProperties
();
if
(
uncommon
==
s_noUncommonProperties
)
{
return
false
;
}
if
(!
uncommon
.
lazyIsByRefLike
.
HasValue
())
{
var
isByRefLike
=
ThreeState
.
False
;
if
(
this
.
TypeKind
==
TypeKind
.
Struct
)
{
if
(
IsWellknownSpans
())
{
isByRefLike
=
ThreeState
.
True
;
}
else
{
var
moduleSymbol
=
this
.
ContainingPEModule
;
var
module
=
moduleSymbol
.
Module
;
isByRefLike
=
module
.
HasIsByRefLikeAttribute
(
_handle
).
ToThreeState
();
}
}
uncommon
.
lazyIsByRefLike
=
isByRefLike
;
}
return
uncommon
.
lazyIsByRefLike
.
Value
();
}
}
//PROTOTYPE(span): Span and ReadonlySpan should have spanLike marker.
// For now assume that any "System.Span" and "System.ReadOnlySpan" structs
// are span-like
private
bool
IsWellknownSpans
()
{
var
originalDef
=
this
.
OriginalDefinition
;
if
(
originalDef
.
Name
!=
"Span"
&&
originalDef
.
Name
!=
"ReadonlySpan"
)
{
return
false
;
}
var
ns
=
originalDef
.
ContainingSymbol
as
NamespaceSymbol
;
if
(
ns
?.
Name
!=
"System"
)
{
return
false
;
}
return
(
object
)
ns
.
ContainingNamespace
!=
null
;
}
internal
override
bool
HasDeclarativeSecurity
{
get
{
return
(
_flags
&
TypeAttributes
.
HasSecurity
)
!=
0
;
}
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
浏览文件 @
df875bfc
...
...
@@ -670,6 +670,14 @@ public override bool IsStatic
}
}
internal
override
bool
IsByRefLikeType
{
get
{
return
(
_flags
.
DeclarationModifiers
&
DeclarationModifiers
.
Ref
)
!=
0
;
}
}
public
override
bool
IsSealed
{
get
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs
浏览文件 @
df875bfc
...
...
@@ -50,8 +50,7 @@ protected void TypeChecks(TypeSymbol type, DiagnosticBag diagnostics)
{
diagnostics
.
Add
(
ErrorCode
.
ERR_FieldCantHaveVoidType
,
TypeSyntax
.
Location
);
}
//PROTOTYPE(span): span-like instance fields are allowed in span-like types, for now allow inany struct
else
if
(
type
.
IsRestrictedType
(
ignoreSpanLikeTypes
:
!
this
.
IsStatic
&&
containingType
.
IsStructType
()))
else
if
(
type
.
IsRestrictedType
(
ignoreSpanLikeTypes
:
!
this
.
IsStatic
&&
containingType
.
IsByRefLikeType
))
{
diagnostics
.
Add
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
TypeSyntax
.
Location
,
type
);
}
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
浏览文件 @
df875bfc
...
...
@@ -1097,6 +1097,12 @@ internal override void AddSynthesizedAttributes(ModuleCompilationState compilati
AddSynthesizedAttribute
(
ref
attributes
,
compilation
.
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_CompilerServices_ExtensionAttribute__ctor
));
}
if
(
this
.
IsByRefLikeType
)
{
//PROTOTYPE(span): should also set [Obsolete] Attribute with a known marker
AddSynthesizedAttribute
(
ref
attributes
,
compilation
.
SynthesizeIsByRefLikeAttribute
());
}
if
(
this
.
Indexers
.
Any
())
{
string
defaultMemberName
=
this
.
Indexers
.
First
().
MetadataName
;
// UNDONE: IndexerNameAttribute
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
浏览文件 @
df875bfc
...
...
@@ -1308,8 +1308,12 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok
var
conversions
=
new
TypeConversions
(
this
.
ContainingAssembly
.
CorLibrary
);
this
.
Type
.
CheckAllConstraints
(
conversions
,
_location
,
diagnostics
);
//PROTOTYPE(span): allow in span-like structs?
if
(
this
.
Type
.
IsRestrictedType
(
ignoreSpanLikeTypes
:
!
this
.
IsAutoProperty
))
// autoproperties can have span-like types only
// inside a span-like type and when not static
var
canReturnSpan
=
!
this
.
IsAutoProperty
||
(!
this
.
IsStatic
&&
this
.
ContainingType
.
IsByRefLikeType
);
if
(
this
.
Type
.
IsRestrictedType
(
ignoreSpanLikeTypes
:
canReturnSpan
))
{
diagnostics
.
Add
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
this
.
CSharpSyntaxNode
.
Type
.
Location
,
this
.
Type
);
}
...
...
src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs
浏览文件 @
df875bfc
...
...
@@ -639,30 +639,10 @@ public virtual NamedTypeSymbol TupleUnderlyingType
/// </remarks>
internal
abstract
bool
IsManagedType
{
get
;
}
//PROTOTYPE(span): this will completely change depending on how span-like types are implemented.
// Span<T> and ReadOnlySpan<T> will be special types (currently they are not always)
// Users may be able to define their own Spanlike types, but that is completely NYI
// For now we will be simply looking at "System.Span" and "System.ReadOnlySpan" names
/// <summary>
/// Returns true if the type
is a Span/ReadOnlySpan
/// Returns true if the type
may contain embedded references
/// </summary>
internal
bool
IsSpanLikeType
()
{
var
originalDef
=
this
.
OriginalDefinition
;
if
(
originalDef
.
Name
!=
"Span"
&&
originalDef
.
Name
!=
"ReadonlySpan"
)
{
return
false
;
}
var
ns
=
originalDef
.
ContainingSymbol
as
NamespaceSymbol
;
if
(
ns
?.
Name
!=
"System"
)
{
return
false
;
}
return
(
object
)
ns
.
ContainingNamespace
!=
null
;
}
internal
virtual
bool
IsByRefLikeType
=>
false
;
#
region
ITypeSymbol
Members
...
...
src/Compilers/CSharp/Portable/Symbols/TypeSymbolExtensions.cs
浏览文件 @
df875bfc
...
...
@@ -935,7 +935,7 @@ internal static bool IsValidV6SwitchGoverningType(this TypeSymbol type, bool isT
return
ignoreSpanLikeTypes
?
false
:
type
.
Is
SpanLikeType
()
;
type
.
Is
ByRefLikeType
;
}
public
static
bool
IsIntrinsicType
(
this
TypeSymbol
type
)
...
...
src/Compilers/CSharp/Portable/Symbols/Wrapped/WrappedNamedTypeSymbol.cs
浏览文件 @
df875bfc
...
...
@@ -205,6 +205,11 @@ internal override bool IsSerializable
get
{
return
_underlyingType
.
IsSerializable
;
}
}
internal
override
bool
IsByRefLikeType
{
get
{
return
_underlyingType
.
IsByRefLikeType
;
}
}
internal
override
bool
HasDeclarativeSecurity
{
get
{
return
_underlyingType
.
HasDeclarativeSecurity
;
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs
浏览文件 @
df875bfc
...
...
@@ -20,31 +20,59 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests
public
class
SpanStackSafetyTests
:
CompilingTestBase
{
private
static
string
spanSource
=
@"
namespace System
{
public struct Span<T>
public
ref
struct Span<T>
{
public ref T this[int i] => throw null;
public override int GetHashCode() => 1;
}
public struct ReadonlySpan<T>
public
ref
struct ReadonlySpan<T>
{
public ref readonly T this[int i] => throw null;
public override int GetHashCode() => 2;
}
public ref struct SpanLike<T>
{
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Struct)]
public sealed class IsByRefLikeAttribute: Attribute
{
public IsByRefLikeAttribute(){}
}
}
"
;
//PROTOTYPE(span): this will be updated when rules for defining span are implemented
// most likely we would just pick the actual binary/corlib where
// span lives.
private
static
CSharpCompilation
CreateCompilationWithMscorlibAndSpan
(
string
text
,
CSharpCompilationOptions
options
=
null
)
{
var
reference
=
CreateCompilationWithMscorlib45
(
spanSource
,
references
:
new
List
<
MetadataReference
>()
{
MscorlibRef_v4_0_30316_17626
,
SystemCoreRef
,
CSharpRef
},
options
:
TestOptions
.
ReleaseDll
).
EmitToImageReference
();
var
comp
=
CreateCompilationWithMscorlib45
(
text
,
references
:
new
List
<
MetadataReference
>()
{
MscorlibRef_v4_0_30316_17626
,
SystemCoreRef
,
CSharpRef
,
reference
},
options
:
options
??
TestOptions
.
ReleaseExe
);
return
comp
;
}
private
static
CSharpCompilation
CreateCompilationWithMscorlibAndSpanSrc
(
string
text
,
CSharpCompilationOptions
options
=
null
)
{
var
textWitSpan
=
new
string
[]
{
text
,
spanSource
};
var
comp
=
CreateCompilationWithMscorlib45
(
textWitSpan
,
references
:
new
List
<
MetadataReference
>()
{
MscorlibRef_v4_0_30316_17626
,
SystemCoreRef
,
CSharpRef
},
textWitSpan
,
references
:
new
List
<
MetadataReference
>()
{
MscorlibRef_v4_0_30316_17626
,
SystemCoreRef
,
CSharpRef
},
options
:
options
??
TestOptions
.
ReleaseExe
);
return
comp
;
...
...
@@ -62,6 +90,7 @@ static void Main()
{
object x = new Span<int>();
object y = new ReadonlySpan<byte>();
object z = new SpanLike<int>();
}
}
"
;
...
...
@@ -74,7 +103,24 @@ static void Main()
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Span<int>()"
).
WithArguments
(
"System.Span<int>"
,
"object"
).
WithLocation
(
8
,
20
),
// (9,20): error CS0029: Cannot implicitly convert type 'System.ReadonlySpan<byte>' to 'object'
// object y = new ReadonlySpan<byte>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new ReadonlySpan<byte>()"
).
WithArguments
(
"System.ReadonlySpan<byte>"
,
"object"
).
WithLocation
(
9
,
20
)
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new ReadonlySpan<byte>()"
).
WithArguments
(
"System.ReadonlySpan<byte>"
,
"object"
).
WithLocation
(
9
,
20
),
// (10,20): error CS0029: Cannot implicitly convert type 'System.SpanLike<int>' to 'object'
// object z = new SpanLike<int>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new SpanLike<int>()"
).
WithArguments
(
"System.SpanLike<int>"
,
"object"
)
);
comp
=
CreateCompilationWithMscorlibAndSpanSrc
(
text
);
comp
.
VerifyDiagnostics
(
// (8,20): error CS0029: Cannot implicitly convert type 'System.Span<int>' to 'object'
// object x = new Span<int>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new Span<int>()"
).
WithArguments
(
"System.Span<int>"
,
"object"
).
WithLocation
(
8
,
20
),
// (9,20): error CS0029: Cannot implicitly convert type 'System.ReadonlySpan<byte>' to 'object'
// object y = new ReadonlySpan<byte>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new ReadonlySpan<byte>()"
).
WithArguments
(
"System.ReadonlySpan<byte>"
,
"object"
).
WithLocation
(
9
,
20
),
// (10,20): error CS0029: Cannot implicitly convert type 'System.SpanLike<int>' to 'object'
// object z = new SpanLike<int>();
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"new SpanLike<int>()"
).
WithArguments
(
"System.SpanLike<int>"
,
"object"
)
);
}
...
...
@@ -222,7 +268,7 @@ static void M3(in Span<string> ss)
}
[
Fact
]
public
void
Fields
()
public
void
Fields
Span
()
{
var
text
=
@"
using System;
...
...
@@ -236,27 +282,128 @@ static void Main()
public static Span<byte> fs;
public Span<int> fi;
public struct S1
public
ref
struct S1
{
//PROTOTYPE(span): instance Span fields in structs are ok for now, - until span-like types can be declared
public static Span<byte> fs1;
public Span<int> fi1;
}
public struct S2
{
public static Span<byte> fs2;
public Span<int> fi2;
}
}
"
;
CSharpCompilation
comp
=
CreateCompilationWithMscorlibAndSpan
(
text
);
comp
.
VerifyDiagnostics
(
// (16,23): error CS0610: Field or property cannot be of type 'Span<byte>'
// (22,16): error CS0610: Field or property cannot be of type 'Span<int>'
// public Span<int> fi1;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<int>"
).
WithArguments
(
"System.Span<int>"
),
// (21,23): error CS0610: Field or property cannot be of type 'Span<byte>'
// public static Span<byte> fs1;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<byte>"
).
WithArguments
(
"System.Span<byte>"
)
.
WithLocation
(
16
,
23
)
,
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<byte>"
).
WithArguments
(
"System.Span<byte>"
),
// (10,19): error CS0610: Field or property cannot be of type 'Span<byte>'
// public static Span<byte> fs;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<byte>"
).
WithArguments
(
"System.Span<byte>"
)
.
WithLocation
(
10
,
19
)
,
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<byte>"
).
WithArguments
(
"System.Span<byte>"
),
// (11,12): error CS0610: Field or property cannot be of type 'Span<int>'
// public Span<int> fi;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<int>"
).
WithArguments
(
"System.Span<int>"
).
WithLocation
(
11
,
12
)
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<int>"
).
WithArguments
(
"System.Span<int>"
),
// (15,23): error CS0610: Field or property cannot be of type 'Span<byte>'
// public static Span<byte> fs1;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<byte>"
).
WithArguments
(
"System.Span<byte>"
)
);
comp
=
CreateCompilationWithMscorlibAndSpanSrc
(
text
);
comp
.
VerifyDiagnostics
(
// (22,16): error CS0610: Field or property cannot be of type 'Span<int>'
// public Span<int> fi1;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<int>"
).
WithArguments
(
"System.Span<int>"
),
// (21,23): error CS0610: Field or property cannot be of type 'Span<byte>'
// public static Span<byte> fs1;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<byte>"
).
WithArguments
(
"System.Span<byte>"
),
// (10,19): error CS0610: Field or property cannot be of type 'Span<byte>'
// public static Span<byte> fs;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<byte>"
).
WithArguments
(
"System.Span<byte>"
),
// (11,12): error CS0610: Field or property cannot be of type 'Span<int>'
// public Span<int> fi;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<int>"
).
WithArguments
(
"System.Span<int>"
),
// (15,23): error CS0610: Field or property cannot be of type 'Span<byte>'
// public static Span<byte> fs1;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"Span<byte>"
).
WithArguments
(
"System.Span<byte>"
)
);
}
[
Fact
]
public
void
FieldsSpanLike
()
{
var
text
=
@"
using System;
public class Program
{
static void Main()
{
}
public static SpanLike<byte> fs;
public SpanLike<int> fi;
public ref struct S1
{
public static SpanLike<byte> fs1;
public SpanLike<int> fi1;
}
public struct S2
{
public static SpanLike<byte> fs2;
public SpanLike<int> fi2;
}
}
"
;
CSharpCompilation
comp
=
CreateCompilationWithMscorlibAndSpan
(
text
);
comp
.
VerifyDiagnostics
(
// (22,16): error CS0610: Field or property cannot be of type 'SpanLike<int>'
// public SpanLike<int> fi2;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<int>"
).
WithArguments
(
"System.SpanLike<int>"
).
WithLocation
(
22
,
16
),
// (21,23): error CS0610: Field or property cannot be of type 'SpanLike<byte>'
// public static SpanLike<byte> fs2;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<byte>"
).
WithArguments
(
"System.SpanLike<byte>"
).
WithLocation
(
21
,
23
),
// (10,19): error CS0610: Field or property cannot be of type 'SpanLike<byte>'
// public static SpanLike<byte> fs;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<byte>"
).
WithArguments
(
"System.SpanLike<byte>"
).
WithLocation
(
10
,
19
),
// (11,12): error CS0610: Field or property cannot be of type 'SpanLike<int>'
// public SpanLike<int> fi;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<int>"
).
WithArguments
(
"System.SpanLike<int>"
).
WithLocation
(
11
,
12
),
// (15,23): error CS0610: Field or property cannot be of type 'SpanLike<byte>'
// public static SpanLike<byte> fs1;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<byte>"
).
WithArguments
(
"System.SpanLike<byte>"
).
WithLocation
(
15
,
23
)
);
comp
=
CreateCompilationWithMscorlibAndSpanSrc
(
text
);
comp
.
VerifyDiagnostics
(
// (22,16): error CS0610: Field or property cannot be of type 'SpanLike<int>'
// public SpanLike<int> fi2;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<int>"
).
WithArguments
(
"System.SpanLike<int>"
).
WithLocation
(
22
,
16
),
// (21,23): error CS0610: Field or property cannot be of type 'SpanLike<byte>'
// public static SpanLike<byte> fs2;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<byte>"
).
WithArguments
(
"System.SpanLike<byte>"
).
WithLocation
(
21
,
23
),
// (10,19): error CS0610: Field or property cannot be of type 'SpanLike<byte>'
// public static SpanLike<byte> fs;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<byte>"
).
WithArguments
(
"System.SpanLike<byte>"
).
WithLocation
(
10
,
19
),
// (11,12): error CS0610: Field or property cannot be of type 'SpanLike<int>'
// public SpanLike<int> fi;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<int>"
).
WithArguments
(
"System.SpanLike<int>"
).
WithLocation
(
11
,
12
),
// (15,23): error CS0610: Field or property cannot be of type 'SpanLike<byte>'
// public static SpanLike<byte> fs1;
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"SpanLike<byte>"
).
WithArguments
(
"System.SpanLike<byte>"
).
WithLocation
(
15
,
23
)
);
}
...
...
src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs
浏览文件 @
df875bfc
...
...
@@ -559,7 +559,8 @@ public void AllWellKnownTypes()
case
WellKnownType
.
System_FormattableString
:
case
WellKnownType
.
System_Runtime_CompilerServices_FormattableStringFactory
:
case
WellKnownType
.
System_Runtime_CompilerServices_ReadOnlyAttribute
:
// Not yet in the platform.
case
WellKnownType
.
System_Runtime_CompilerServices_IsByRefLikeAttribute
:
// Not yet in the platform.
case
WellKnownType
.
Microsoft_CodeAnalysis_Runtime_Instrumentation
:
// Not always available.
continue
;
...
...
@@ -861,6 +862,7 @@ public void AllWellKnownTypeMembers()
continue
;
case
WellKnownMember
.
Microsoft_CodeAnalysis_Runtime_Instrumentation__CreatePayload
:
case
WellKnownMember
.
System_Runtime_CompilerServices_ReadOnlyAttribute__ctor
:
case
WellKnownMember
.
System_Runtime_CompilerServices_IsByRefLikeAttribute__ctor
:
// Not always available.
continue
;
}
...
...
src/Compilers/CSharp/Test/Syntax/Parsing/RefStructs.cs
浏览文件 @
df875bfc
...
...
@@ -20,7 +20,7 @@ protected override SyntaxTree ParseTree(string text, CSharpParseOptions options)
}
[
Fact
]
public
void
RefStruct
001
()
public
void
RefStruct
Simple
()
{
var
text
=
@"
class Program
...
...
@@ -29,6 +29,49 @@ class Program
public ref struct S2{}
}
"
;
var
comp
=
CreateCompilationWithMscorlib45
(
text
,
parseOptions
:
TestOptions
.
Regular
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7
),
options
:
TestOptions
.
DebugDll
);
comp
.
VerifyDiagnostics
(
);
}
[
Fact
]
public
void
RefStructErr
()
{
var
text
=
@"
class Program
{
ref class S1{}
public ref unsafe struct S2{}
}
"
;
var
comp
=
CreateCompilationWithMscorlib45
(
text
,
parseOptions
:
TestOptions
.
Regular
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7
),
options
:
TestOptions
.
DebugDll
);
comp
.
VerifyDiagnostics
(
// (4,9): error CS1031: Type expected
// ref class S1{}
Diagnostic
(
ErrorCode
.
ERR_TypeExpected
,
"class"
).
WithLocation
(
4
,
9
),
// (6,16): error CS1031: Type expected
// public ref unsafe struct S2{}
Diagnostic
(
ErrorCode
.
ERR_TypeExpected
,
"unsafe"
).
WithLocation
(
6
,
16
),
// (6,30): error CS0227: Unsafe code may only appear if compiling with /unsafe
// public ref unsafe struct S2{}
Diagnostic
(
ErrorCode
.
ERR_IllegalUnsafe
,
"S2"
).
WithLocation
(
6
,
30
)
);
}
[
Fact
]
public
void
RefStructPartial
()
{
var
text
=
@"
class Program
{
partial ref struct S1{}
partial ref struct S1{}
}
"
;
var
comp
=
CreateCompilationWithMscorlib45
(
text
,
parseOptions
:
TestOptions
.
Regular
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7
),
options
:
TestOptions
.
DebugDll
);
...
...
src/Compilers/Core/Portable/MetadataReader/PEModule.cs
浏览文件 @
df875bfc
...
...
@@ -1024,6 +1024,11 @@ internal bool HasTupleElementNamesAttribute(EntityHandle token, out ImmutableArr
return
TryExtractStringArrayValueFromAttribute
(
info
.
Handle
,
out
tupleElementNames
);
}
internal
bool
HasIsByRefLikeAttribute
(
EntityHandle
token
)
{
return
FindTargetAttribute
(
token
,
AttributeDescription
.
IsByRefLikeAttribute
).
HasValue
;
}
internal
bool
HasDeprecatedOrObsoleteAttribute
(
EntityHandle
token
,
out
ObsoleteAttributeData
obsoleteData
)
{
AttributeInfo
info
;
...
...
src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs
浏览文件 @
df875bfc
...
...
@@ -356,6 +356,7 @@ static AttributeDescription()
private
static
readonly
byte
[][]
s_signaturesOfObsoleteAttribute
=
{
s_signature_HasThis_Void
,
s_signature_HasThis_Void_String
,
s_signature_HasThis_Void_String_Boolean
};
private
static
readonly
byte
[][]
s_signaturesOfDynamicAttribute
=
{
s_signature_HasThis_Void
,
s_signature_HasThis_Void_SzArray_Boolean
};
private
static
readonly
byte
[][]
s_signaturesOfTupleElementNamesAttribute
=
{
s_signature_HasThis_Void
,
s_signature_HasThis_Void_SzArray_String
};
private
static
readonly
byte
[][]
s_signaturesOfIsByRefLikeAttribute
=
{
s_signature_HasThis_Void
};
private
static
readonly
byte
[][]
s_signaturesOfDebuggerHiddenAttribute
=
{
s_signature_HasThis_Void
};
private
static
readonly
byte
[][]
s_signaturesOfDebuggerNonUserCodeAttribute
=
{
s_signature_HasThis_Void
};
private
static
readonly
byte
[][]
s_signaturesOfDebuggerStepperBoundaryAttribute
=
{
s_signature_HasThis_Void
};
...
...
@@ -485,6 +486,7 @@ static AttributeDescription()
internal
static
readonly
AttributeDescription
TypeLibTypeAttribute
=
new
AttributeDescription
(
"System.Runtime.InteropServices"
,
"TypeLibTypeAttribute"
,
s_signaturesOfTypeLibTypeAttribute
);
internal
static
readonly
AttributeDescription
DynamicAttribute
=
new
AttributeDescription
(
"System.Runtime.CompilerServices"
,
"DynamicAttribute"
,
s_signaturesOfDynamicAttribute
);
internal
static
readonly
AttributeDescription
TupleElementNamesAttribute
=
new
AttributeDescription
(
"System.Runtime.CompilerServices"
,
"TupleElementNamesAttribute"
,
s_signaturesOfTupleElementNamesAttribute
);
internal
static
readonly
AttributeDescription
IsByRefLikeAttribute
=
new
AttributeDescription
(
"System.Runtime.CompilerServices"
,
"IsByRefLikeAttribute"
,
s_signaturesOfIsByRefLikeAttribute
);
internal
static
readonly
AttributeDescription
DebuggerHiddenAttribute
=
new
AttributeDescription
(
"System.Diagnostics"
,
"DebuggerHiddenAttribute"
,
s_signaturesOfDebuggerHiddenAttribute
);
internal
static
readonly
AttributeDescription
DebuggerNonUserCodeAttribute
=
new
AttributeDescription
(
"System.Diagnostics"
,
"DebuggerNonUserCodeAttribute"
,
s_signaturesOfDebuggerNonUserCodeAttribute
);
internal
static
readonly
AttributeDescription
DebuggerStepperBoundaryAttribute
=
new
AttributeDescription
(
"System.Diagnostics"
,
"DebuggerStepperBoundaryAttribute"
,
s_signaturesOfDebuggerStepperBoundaryAttribute
);
...
...
src/Compilers/Core/Portable/WellKnownMember.cs
浏览文件 @
df875bfc
...
...
@@ -418,6 +418,8 @@ internal enum WellKnownMember
System_Runtime_CompilerServices_ReadOnlyAttribute__ctor
,
System_Runtime_CompilerServices_IsByRefLikeAttribute__ctor
,
Count
}
}
src/Compilers/Core/Portable/WellKnownMembers.cs
浏览文件 @
df875bfc
...
...
@@ -2885,6 +2885,13 @@ static WellKnownMembers()
0
,
// Arity
0
,
// Method Signature
(
byte
)
SignatureTypeCode
.
TypeHandle
,
(
byte
)
SpecialType
.
System_Void
,
// System_Runtime_CompilerServices_IsByRefLikeAttribute__ctor
(
byte
)(
MemberFlags
.
Constructor
),
// Flags
(
byte
)
WellKnownType
.
ExtSentinel
,
(
byte
)(
WellKnownType
.
System_Runtime_CompilerServices_IsByRefLikeAttribute
-
WellKnownType
.
ExtSentinel
),
// DeclaringTypeId
0
,
// Arity
0
,
// Method Signature
(
byte
)
SignatureTypeCode
.
TypeHandle
,
(
byte
)
SpecialType
.
System_Void
,
};
string
[]
allNames
=
new
string
[(
int
)
WellKnownMember
.
Count
]
...
...
@@ -3244,6 +3251,7 @@ static WellKnownMembers()
"Format"
,
// System_String__Format_IFormatProvider
"CreatePayload"
,
// Microsoft_CodeAnalysis_Runtime_Instrumentation__CreatePayload
".ctor"
,
// System_Runtime_CompilerServices_ReadOnlyAttribute__ctor
".ctor"
,
// System_Runtime_CompilerServices_IsByRefLikeAttribute__ctor
};
s_descriptors
=
MemberDescriptor
.
InitializeFromStream
(
new
System
.
IO
.
MemoryStream
(
initializationBytes
,
writable
:
false
),
allNames
);
...
...
@@ -3272,6 +3280,7 @@ internal static bool IsSynthesizedAttributeOptional(WellKnownMember attributeMem
case
WellKnownMember
.
System_STAThreadAttribute__ctor
:
case
WellKnownMember
.
System_Runtime_CompilerServices_AsyncStateMachineAttribute__ctor
:
case
WellKnownMember
.
System_Runtime_CompilerServices_IteratorStateMachineAttribute__ctor
:
case
WellKnownMember
.
System_Runtime_CompilerServices_IsByRefLikeAttribute__ctor
:
return
true
;
default
:
...
...
src/Compilers/Core/Portable/WellKnownTypes.cs
浏览文件 @
df875bfc
...
...
@@ -265,6 +265,7 @@ internal enum WellKnownType
Microsoft_CodeAnalysis_Runtime_Instrumentation
,
System_Runtime_CompilerServices_ReadOnlyAttribute
,
System_Runtime_CompilerServices_IsByRefLikeAttribute
,
NextAvailable
,
}
...
...
@@ -524,6 +525,7 @@ internal static class WellKnownTypes
"Microsoft.CodeAnalysis.Runtime.Instrumentation"
,
"System.Runtime.CompilerServices.ReadOnlyAttribute"
,
"System.Runtime.CompilerServices.IsByRefLikeAttribute"
,
};
private
readonly
static
Dictionary
<
string
,
WellKnownType
>
s_nameToTypeIdMap
=
new
Dictionary
<
string
,
WellKnownType
>((
int
)
Count
);
...
...
src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb
浏览文件 @
df875bfc
...
...
@@ -508,7 +508,8 @@ End Namespace
' Not a real type
Continue
For
Case
WellKnownType
.
Microsoft_CodeAnalysis_Runtime_Instrumentation
,
WellKnownType
.
System_Runtime_CompilerServices_ReadOnlyAttribute
WellKnownType
.
System_Runtime_CompilerServices_ReadOnlyAttribute
,
WellKnownType
.
System_Runtime_CompilerServices_IsByRefLikeAttribute
' Not always available.
Continue
For
End
Select
...
...
@@ -544,7 +545,8 @@ End Namespace
' Not a real type
Continue
For
Case
WellKnownType
.
Microsoft_CodeAnalysis_Runtime_Instrumentation
,
WellKnownType
.
System_Runtime_CompilerServices_ReadOnlyAttribute
WellKnownType
.
System_Runtime_CompilerServices_ReadOnlyAttribute
,
WellKnownType
.
System_Runtime_CompilerServices_IsByRefLikeAttribute
' Not always available.
Continue
For
End
Select
...
...
@@ -583,7 +585,8 @@ End Namespace
' Not available yet, but will be in upcoming release.
Continue
For
Case
WellKnownMember
.
Microsoft_CodeAnalysis_Runtime_Instrumentation__CreatePayload
,
WellKnownMember
.
System_Runtime_CompilerServices_ReadOnlyAttribute__ctor
WellKnownMember
.
System_Runtime_CompilerServices_ReadOnlyAttribute__ctor
,
WellKnownMember
.
System_Runtime_CompilerServices_IsByRefLikeAttribute__ctor
' Not always available.
Continue
For
End
Select
...
...
@@ -664,7 +667,8 @@ End Namespace
' Not available yet, but will be in upcoming release.
Continue
For
Case
WellKnownMember
.
Microsoft_CodeAnalysis_Runtime_Instrumentation__CreatePayload
,
WellKnownMember
.
System_Runtime_CompilerServices_ReadOnlyAttribute__ctor
WellKnownMember
.
System_Runtime_CompilerServices_ReadOnlyAttribute__ctor
,
WellKnownMember
.
System_Runtime_CompilerServices_IsByRefLikeAttribute__ctor
' Not always available.
Continue
For
End
Select
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录