Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
31fa3ffb
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,发现更多精彩内容 >>
提交
31fa3ffb
编写于
7月 10, 2015
作者:
E
Evan Hauck
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Disallow invocations of local functions with dynamic arguments
上级
40a1d1ce
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
79 addition
and
9 deletion
+79
-9
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
+5
-0
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
+10
-1
src/Compilers/CSharp/Portable/CSharpResources.resx
src/Compilers/CSharp/Portable/CSharpResources.resx
+4
-1
src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
...ompilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
+1
-1
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
+1
-0
src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
...lers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
+58
-6
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
浏览文件 @
31fa3ffb
...
...
@@ -259,6 +259,11 @@ private BoundExpression BindArgListOperator(InvocationExpressionSyntax node, Dia
BoundMethodGroup
methodGroup
=
(
BoundMethodGroup
)
expression
;
BoundExpression
receiver
=
methodGroup
.
ReceiverOpt
;
if
((
methodGroup
.
LookupSymbolOpt
as
MethodSymbol
)?.
MethodKind
==
MethodKind
.
LocalFunction
)
{
diagnostics
.
Add
(
ErrorCode
.
ERR_DynamicLocalFunctionParameter
,
node
.
Location
,
methodGroup
.
Syntax
);
}
// receiver is null if we are calling a static method declared on an outer class via its simple name:
if
(
receiver
!=
null
)
{
...
...
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
浏览文件 @
31fa3ffb
...
...
@@ -3409,6 +3409,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to Cannot invoke the local function '{0}' with dynamic parameters..
/// </summary>
internal static string ERR_DynamicLocalFunctionParameter {
get {
return ResourceManager.GetString("ERR_DynamicLocalFunctionParameter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?.
/// </summary>
...
...
@@ -7559,7 +7568,7 @@ internal class CSharpResources {
}
/// <summary>
/// Looks up a localized string similar to Cannot infer the return type of
{0}
due to differing return types..
/// Looks up a localized string similar to Cannot infer the return type of
'{0}'
due to differing return types..
/// </summary>
internal static string ERR_ReturnTypesDontMatch {
get {
...
...
src/Compilers/CSharp/Portable/CSharpResources.resx
浏览文件 @
31fa3ffb
...
...
@@ -4645,6 +4645,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>
An expression tree may not contain a local function or a reference to a local function
</value>
</data>
<data
name=
"ERR_ReturnTypesDontMatch"
xml:space=
"preserve"
>
<value>
Cannot infer the return type of {0} due to differing return types.
</value>
<value>
Cannot infer the return type of '{0}' due to differing return types.
</value>
</data>
<data
name=
"ERR_DynamicLocalFunctionParameter"
xml:space=
"preserve"
>
<value>
Cannot invoke the local function '{0}' with dynamic parameters.
</value>
</data>
</root>
\ No newline at end of file
src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
浏览文件 @
31fa3ffb
...
...
@@ -999,7 +999,7 @@ public static Cci.TypeMemberVisibility MemberVisibility(Symbol symbol)
return
Cci
.
TypeMemberVisibility
.
Public
;
case
Accessibility
.
Private
:
if
(
symbol
.
ContainingType
.
TypeKind
==
TypeKind
.
Submission
)
if
(
symbol
.
ContainingType
?
.
TypeKind
==
TypeKind
.
Submission
)
{
// top-level private member:
return
Cci
.
TypeMemberVisibility
.
Public
;
...
...
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
浏览文件 @
31fa3ffb
...
...
@@ -1313,5 +1313,6 @@ internal enum ErrorCode
ERR_ConstantStringTooLong
=
8095
,
ERR_ExpressionTreeContainsLocalFunction
=
8096
,
ERR_ReturnTypesDontMatch
=
8097
,
ERR_DynamicLocalFunctionParameter
=
8098
,
}
}
src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
浏览文件 @
31fa3ffb
...
...
@@ -2129,18 +2129,49 @@ void Local()
VerifyOutputInMain
(
source
,
"2 Program"
,
"System"
);
}
[
Fact
(
Skip
=
"Dynamic local function arguments not supported yet"
)
]
[
Fact
]
public
void
DynamicArgument
()
{
var
source
=
@"
void Local(int x)
using System;
class Program
{
Console.Write(x);
static void Main()
{
void Local(int x)
{
Console.Write(x);
}
dynamic val = 2;
Local(val);
}
}
dynamic val = 2;
Local(val);
"
;
VerifyOutputInMain
(
source
,
"2"
,
"System"
);
VerifyDiagnostics
(
source
,
// (12,9): error CS8098: Cannot invoke the local function 'Local' with dynamic parameters.
// Local(val);
Diagnostic
(
ErrorCode
.
ERR_DynamicLocalFunctionParameter
,
"Local(val)"
).
WithArguments
(
"Local"
).
WithLocation
(
12
,
9
)
);
}
[
Fact
]
public
void
DynamicParameter
()
{
var
source
=
@"
using System;
class Program
{
static void Main()
{
void Local(dynamic x)
{
Console.Write(x);
}
Local(2);
}
}
"
;
VerifyOutput
(
source
,
"2"
);
}
[
Fact
]
...
...
@@ -2169,6 +2200,27 @@ var RetDyn()
VerifyOutputInMain
(
source
,
"2"
,
"System"
);
}
[
Fact
]
public
void
DynamicDelegate
()
{
var
source
=
@"
using System;
class Program
{
static void Main()
{
dynamic Local(dynamic x)
{
return x;
}
dynamic local = (Func<dynamic, dynamic>)Local;
Console.Write(local(2));
}
}
"
;
VerifyOutput
(
source
,
"2"
);
}
[
Fact
]
public
void
Nameof
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录