Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
ba9e1121
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,发现更多精彩内容 >>
提交
ba9e1121
编写于
4月 05, 2019
作者:
R
Rikki Gibson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes from feedback
上级
654ff743
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
9 deletion
+33
-9
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs
...p/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs
+16
-5
src/Compilers/CSharp/Test/Semantic/Semantics/ReadOnlyStructsTests.cs
...rs/CSharp/Test/Semantic/Semantics/ReadOnlyStructsTests.cs
+17
-4
未找到文件。
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs
浏览文件 @
ba9e1121
...
@@ -422,13 +422,24 @@ internal Accessibility LocalAccessibility
...
@@ -422,13 +422,24 @@ internal Accessibility LocalAccessibility
/// <summary>
/// <summary>
/// Indicates whether this accessor is readonly due to reasons scoped to itself and its containing property.
/// Indicates whether this accessor is readonly due to reasons scoped to itself and its containing property.
/// </summary>
/// </summary>
internal
override
bool
IsDeclaredReadOnly
=>
LocalDeclaredReadOnly
||
_property
.
HasReadOnlyModifier
||
IsReadOnlyAutoGetter
;
internal
override
bool
IsDeclaredReadOnly
{
get
{
return
LocalDeclaredReadOnly
||
_property
.
HasReadOnlyModifier
||
isReadOnlyAutoGetter
();
private
bool
IsReadOnlyAutoGetter
=>
ContainingType
.
IsStructType
()
&&
!
_property
.
IsStatic
&&
_isAutoPropertyAccessor
&&
MethodKind
==
MethodKind
.
PropertyGet
&&
!
IsBadNetModule
;
bool
isReadOnlyAutoGetter
()
=>
ContainingType
.
IsStructType
()
&&
!
_property
.
IsStatic
&&
_isAutoPropertyAccessor
&&
MethodKind
==
MethodKind
.
PropertyGet
&&
!
isBadNetModule
();
// We can't emit the synthesized attribute for netmodules, so in this case we consider auto-getters **not** implicitly readonly.
// We can't emit the synthesized attribute for netmodules, so in this case we consider auto-getters **not** implicitly readonly.
private
bool
IsBadNetModule
=>
DeclaringCompilation
.
Options
.
OutputKind
==
OutputKind
.
NetModule
&&
bool
isBadNetModule
()
=>
DeclaringCompilation
.
Options
.
OutputKind
==
OutputKind
.
NetModule
&&
DeclaringCompilation
.
GetWellKnownType
(
WellKnownType
.
System_Runtime_CompilerServices_IsReadOnlyAttribute
)
is
MissingMetadataTypeSymbol
;
DeclaringCompilation
.
GetWellKnownType
(
WellKnownType
.
System_Runtime_CompilerServices_IsReadOnlyAttribute
)
is
MissingMetadataTypeSymbol
;
}
}
private
DeclarationModifiers
MakeModifiers
(
AccessorDeclarationSyntax
syntax
,
bool
isExplicitInterfaceImplementation
,
private
DeclarationModifiers
MakeModifiers
(
AccessorDeclarationSyntax
syntax
,
bool
isExplicitInterfaceImplementation
,
bool
hasBody
,
Location
location
,
DiagnosticBag
diagnostics
,
out
bool
modifierErrors
)
bool
hasBody
,
Location
location
,
DiagnosticBag
diagnostics
,
out
bool
modifierErrors
)
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/ReadOnlyStructsTests.cs
浏览文件 @
ba9e1121
...
@@ -1453,8 +1453,18 @@ public struct S
...
@@ -1453,8 +1453,18 @@ public struct S
public int P1 { get; private set; }
public int P1 { get; private set; }
}
}
"
;
"
;
var
comp
=
CreateCompilation
(
csharp
,
options
:
TestOptions
.
DebugModule
,
targetFramework
:
TargetFramework
.
Mscorlib45
);
var
moduleMetadata
=
CreateCompilation
(
csharp
,
options
:
TestOptions
.
DebugModule
,
targetFramework
:
TargetFramework
.
Mscorlib45
).
EmitToImageReference
();
comp
.
VerifyDiagnostics
();
var
moduleComp
=
CreateCompilation
(
""
,
new
[]
{
moduleMetadata
});
var
moduleGetterAttributes
=
moduleComp
.
GetMember
<
PropertySymbol
>(
"S.P1"
).
GetMethod
.
GetAttributes
();
Assert
.
Equal
(
1
,
moduleGetterAttributes
.
Length
);
Assert
.
Equal
(
"CompilerGeneratedAttribute"
,
moduleGetterAttributes
[
0
].
AttributeClass
.
Name
);
var
dllMetadata
=
CreateCompilation
(
csharp
,
options
:
TestOptions
.
DebugDll
,
targetFramework
:
TargetFramework
.
Mscorlib45
).
EmitToImageReference
();
var
dllComp
=
CreateCompilation
(
""
,
new
[]
{
dllMetadata
});
var
dllGetterAttributes
=
dllComp
.
GetMember
<
PropertySymbol
>(
"S.P1"
).
GetMethod
.
GetAttributes
();
Assert
.
Equal
(
2
,
dllGetterAttributes
.
Length
);
Assert
.
Equal
(
"IsReadOnlyAttribute"
,
dllGetterAttributes
[
0
].
AttributeClass
.
Name
);
Assert
.
Equal
(
"CompilerGeneratedAttribute"
,
dllGetterAttributes
[
1
].
AttributeClass
.
Name
);
}
}
[
Fact
]
[
Fact
]
...
@@ -1466,11 +1476,14 @@ public struct S
...
@@ -1466,11 +1476,14 @@ public struct S
public int P1 { readonly get; private set; }
public int P1 { readonly get; private set; }
}
}
"
;
"
;
var
c
omp
=
CreateCompilation
(
csharp
,
options
:
TestOptions
.
DebugModule
,
targetFramework
:
TargetFramework
.
Mscorlib45
);
var
moduleC
omp
=
CreateCompilation
(
csharp
,
options
:
TestOptions
.
DebugModule
,
targetFramework
:
TargetFramework
.
Mscorlib45
);
c
omp
.
VerifyDiagnostics
(
moduleC
omp
.
VerifyDiagnostics
(
// (4,30): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsReadOnlyAttribute' is not defined or imported
// (4,30): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsReadOnlyAttribute' is not defined or imported
// public int P1 { readonly get; private set; }
// public int P1 { readonly get; private set; }
Diagnostic
(
ErrorCode
.
ERR_PredefinedTypeNotFound
,
"get"
).
WithArguments
(
"System.Runtime.CompilerServices.IsReadOnlyAttribute"
).
WithLocation
(
4
,
30
));
Diagnostic
(
ErrorCode
.
ERR_PredefinedTypeNotFound
,
"get"
).
WithArguments
(
"System.Runtime.CompilerServices.IsReadOnlyAttribute"
).
WithLocation
(
4
,
30
));
var
dllComp
=
CreateCompilation
(
csharp
,
options
:
TestOptions
.
DebugDll
,
targetFramework
:
TargetFramework
.
Mscorlib45
);
dllComp
.
VerifyDiagnostics
();
}
}
[
Fact
]
[
Fact
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录