Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
0846ba67
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,发现更多精彩内容 >>
提交
0846ba67
编写于
9月 21, 2017
作者:
V
Vladimir Sadov
提交者:
GitHub
9月 21, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #22275 from VSadov/refFixes001
Not poisoning restricted types known to be stack only.
上级
eaea4801
269cc0f5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
138 addition
and
7 deletion
+138
-7
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
...s/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
+1
-1
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs
...CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs
+86
-6
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs
+51
-0
未找到文件。
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
浏览文件 @
0846ba67
...
...
@@ -1131,7 +1131,7 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r
// we will not emit Obsolete even if Deprecated or Experimental was used.
// we do not want to get into a scenario where different kinds of deprecation are combined together.
//
if
(
obsoleteData
==
null
)
if
(
obsoleteData
==
null
&&
!
this
.
IsRestrictedType
(
ignoreSpanLikeTypes
:
true
)
)
{
AddSynthesizedAttribute
(
ref
attributes
,
compilation
.
TrySynthesizeAttribute
(
WellKnownMember
.
System_ObsoleteAttribute__ctor
,
ImmutableArray
.
Create
(
...
...
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsByRefLike.cs
浏览文件 @
0846ba67
...
...
@@ -941,19 +941,99 @@ void Method()
);
}
private
static
void
AssertReferencedIsByRefLikeAttributes
(
Accessibility
accessibility
,
ImmutableArray
<
CSharpAttributeData
>
attributes
,
string
assemblyName
)
[
WorkItem
(
22198
,
"https://github.com/dotnet/roslyn/issues/22198"
)]
[
Fact
]
public
void
SpecialTypes_CorLib
()
{
Assert
.
Equal
(
2
,
attributes
.
Count
());
var
source1
=
@"
namespace System
{
public class Object { }
public class String { }
public struct Void { }
public class ValueType { }
public struct Int32 { }
public struct Boolean { }
public struct Decimal { }
public class Attribute{ }
public class ObsoleteAttribute: Attribute
{
public ObsoleteAttribute(string message, bool error){}
}
public ref struct TypedReference { }
public ref struct ArgIterator { }
public ref struct RuntimeArgumentHandle { }
public ref struct NotTypedReference { }
}"
;
var
compilation1
=
CreateCompilation
(
source1
,
assemblyName
:
GetUniqueName
());
CompileAndVerify
(
compilation1
,
verify
:
false
,
symbolValidator
:
module
=>
{
var
type
=
module
.
ContainingAssembly
.
GetTypeByMetadataName
(
"System.TypedReference"
);
Assert
.
True
(
type
.
IsByRefLikeType
);
AssertReferencedIsByRefLikeAttributes
(
Accessibility
.
Internal
,
type
.
GetAttributes
(),
module
.
ContainingAssembly
.
Name
,
hasObsolete
:
false
);
type
=
module
.
ContainingAssembly
.
GetTypeByMetadataName
(
"System.ArgIterator"
);
Assert
.
True
(
type
.
IsByRefLikeType
);
AssertReferencedIsByRefLikeAttributes
(
Accessibility
.
Internal
,
type
.
GetAttributes
(),
module
.
ContainingAssembly
.
Name
,
hasObsolete
:
false
);
type
=
module
.
ContainingAssembly
.
GetTypeByMetadataName
(
"System.RuntimeArgumentHandle"
);
Assert
.
True
(
type
.
IsByRefLikeType
);
AssertReferencedIsByRefLikeAttributes
(
Accessibility
.
Internal
,
type
.
GetAttributes
(),
module
.
ContainingAssembly
.
Name
,
hasObsolete
:
false
);
type
=
module
.
ContainingAssembly
.
GetTypeByMetadataName
(
"System.NotTypedReference"
);
Assert
.
True
(
type
.
IsByRefLikeType
);
// control case. Not a special type.
AssertReferencedIsByRefLikeAttributes
(
Accessibility
.
Internal
,
type
.
GetAttributes
(),
module
.
ContainingAssembly
.
Name
,
hasObsolete
:
true
);
});
}
[
Fact
]
public
void
SpecialTypes_NotCorLib
()
{
var
text
=
@"
namespace System
{
public ref struct TypedReference { }
}
"
;
CompileAndVerify
(
text
,
verify
:
false
,
symbolValidator
:
module
=>
{
var
type
=
module
.
ContainingAssembly
.
GetTypeByMetadataName
(
"System.TypedReference"
);
Assert
.
True
(
type
.
IsByRefLikeType
);
AssertReferencedIsByRefLikeAttributes
(
Accessibility
.
Internal
,
type
.
GetAttributes
(),
module
.
ContainingAssembly
.
Name
);
});
}
private
static
void
AssertReferencedIsByRefLikeAttributes
(
Accessibility
accessibility
,
ImmutableArray
<
CSharpAttributeData
>
attributes
,
string
assemblyName
,
bool
hasObsolete
=
true
)
{
Assert
.
Equal
(
hasObsolete
?
2
:
1
,
attributes
.
Count
());
var
attributeType
=
attributes
[
0
].
AttributeClass
;
Assert
.
Equal
(
"System.Runtime.CompilerServices.IsByRefLikeAttribute"
,
attributeType
.
ToDisplayString
());
Assert
.
Equal
(
assemblyName
,
attributeType
.
ContainingAssembly
.
Name
);
Assert
.
Equal
(
accessibility
,
attributeType
.
DeclaredAccessibility
);
var
attribute
=
attributes
[
1
];
Assert
.
Equal
(
"System.ObsoleteAttribute"
,
attribute
.
AttributeClass
.
ToDisplayString
());
Assert
.
Equal
(
"Types with embedded references are not supported in this version of your compiler."
,
attribute
.
ConstructorArguments
.
ElementAt
(
0
).
Value
);
Assert
.
Equal
(
false
,
attribute
.
ConstructorArguments
.
ElementAt
(
1
).
Value
);
if
(
hasObsolete
)
{
var
attribute
=
attributes
[
1
];
Assert
.
Equal
(
"System.ObsoleteAttribute"
,
attribute
.
AttributeClass
.
ToDisplayString
());
Assert
.
Equal
(
"Types with embedded references are not supported in this version of your compiler."
,
attribute
.
ConstructorArguments
.
ElementAt
(
0
).
Value
);
Assert
.
Equal
(
false
,
attribute
.
ConstructorArguments
.
ElementAt
(
1
).
Value
);
}
}
private
static
void
AssertNotReferencedIsByRefLikeAttribute
(
ImmutableArray
<
CSharpAttributeData
>
attributes
)
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenMscorlib.cs
浏览文件 @
0846ba67
...
...
@@ -373,6 +373,57 @@ public static T Read<T>() where T : new()
);
}
[
Fact
()]
public
void
NoTypedRefBox_RefStruct
()
{
var
source1
=
@"namespace System
{
public class Object { }
public class String { }
public struct Void { }
public class ValueType { }
public struct Int32 { }
public struct Boolean { }
public struct Decimal { }
public class Attribute{ }
public class ObsoleteAttribute: Attribute
{
public ObsoleteAttribute(string message, bool error){}
}
// Make the type ref struct. Should work just fine.
public ref struct TypedReference { }
}"
;
var
compilation1
=
CreateCompilation
(
source1
,
assemblyName
:
GetUniqueName
());
var
reference1
=
MetadataReference
.
CreateFromStream
(
compilation1
.
EmitToStream
());
var
source2
=
@"
public class C1
{
public static object rrr;
public static T Read<T>() where T : new()
{
T result = new T();
var refresult = __makeref(result);
rrr = refresult;
rrr = (object)__makeref(result);
return result;
}
}
"
;
var
compilation2
=
CreateCompilation
(
source2
,
new
[]
{
reference1
});
compilation2
.
VerifyDiagnostics
(
// (10,15): error CS0029: Cannot implicitly convert type 'System.TypedReference' to 'object'
// rrr = refresult;
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"refresult"
).
WithArguments
(
"System.TypedReference"
,
"object"
).
WithLocation
(
10
,
15
),
// (11,15): error CS0030: Cannot convert type 'System.TypedReference' to 'object'
// rrr = (object)__makeref(result);
Diagnostic
(
ErrorCode
.
ERR_NoExplicitConv
,
"(object)__makeref(result)"
).
WithArguments
(
"System.TypedReference"
,
"object"
).
WithLocation
(
11
,
15
)
);
}
[
WorkItem
(
530861
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530861"
)]
[
Fact
]
public
void
MissingStringLengthForEach
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录