Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6ab2391a
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,发现更多精彩内容 >>
提交
6ab2391a
编写于
1月 11, 2018
作者:
V
vsadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added more tests
上级
28b182d8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
147 addition
and
1 deletion
+147
-1
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
+1
-1
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs
...pilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs
+38
-0
src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs
src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs
+108
-0
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
浏览文件 @
6ab2391a
...
...
@@ -4272,7 +4272,7 @@ private BoundExpression BindUnexpectedComplexElementInitializer(InitializerExpre
if
(
implicitReceiver
.
Type
.
IsDynamic
())
{
var
hasErrors
=
ReportBadDynamicArguments
(
elementInitializer
,
boundElementInitializerExpressions
,
default
,
diagnostics
,
queryClause
:
null
);
var
hasErrors
=
ReportBadDynamicArguments
(
elementInitializer
,
boundElementInitializerExpressions
,
refKinds
:
default
,
diagnostics
,
queryClause
:
null
);
return
new
BoundDynamicCollectionElementInitializer
(
elementInitializer
,
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs
浏览文件 @
6ab2391a
...
...
@@ -6182,6 +6182,44 @@ public void test()
expectedOutput
:
expectedOutput
);
}
[
Fact
]
public
void
InArguments
()
{
const
string
source
=
@"
using System;
using System.Linq.Expressions;
class C : TestBase
{
readonly static int x = 1;
readonly static int y = 2;
public static int TakesIn(in int x) => x;
public static void Main(string[] args)
{
// writeable field
Expression<Func<int>> e1 = () => TakesIn(x);
System.Console.Write(e1.Compile()());
// readonly field
Expression<Func<int>> e2 = () => TakesIn(in y);
System.Console.Write(e2.Compile()());
// constant
Expression<Func<int>> e3 = () => TakesIn(3);
Check<int>(e3, ""Call(null.[Int32 TakesIn(Int32 ByRef)](Constant(3 Type:System.Int32)) Type:System.Int32)"");
System.Console.Write(e3.Compile()());
}
}"
;
const
string
expectedOutput
=
@"123"
;
CompileAndVerify
(
new
[]
{
source
,
ExpressionTestLibrary
},
new
[]
{
ExpressionAssemblyRef
},
expectedOutput
:
expectedOutput
);
}
#
endregion
Regression
Tests
#
region
helpers
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs
浏览文件 @
6ab2391a
...
...
@@ -3954,5 +3954,113 @@ static void M1()
Diagnostic
(
ErrorCode
.
ERR_InDynamicMethodArg
,
"x"
).
WithLocation
(
8
,
31
)
);
}
[
WorkItem
(
22813
,
"https://github.com/dotnet/roslyn/issues/22813"
)]
[
Fact
]
public
void
InArgumentDynamicLocalFunction
()
{
string
source
=
@"
class C
{
private static void M1(in dynamic x, int y, in dynamic z) => System.Console.WriteLine(x == y);
static void Main()
{
dynamic d = 1;
// Produce an error. This cannot work correctly right now
M1(in d, d = 2, in d);
void M2(in dynamic x, int y, in dynamic z) => System.Console.WriteLine(x == y);
// NOTE: the following could work!!!
//
// Currently any kind of overloading that would require dynamic dispatch is not permitted
// for locals functions and dynamic dispatch is bypassed.
//
// We will still give an error for consistency with the case where the method is an ordinary private method.
// (and also in case if overloading restrictions are relaxed in the future and dispatch becomes necessary)
//
M2(in d, d = 3, in d);
}
}
"
;
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
parseOptions
:
TestOptions
.
Regular7_2
);
comp
.
VerifyEmitDiagnostics
(
// (11,15): error CS8364: Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.
// M1(in d, d = 2, in d);
Diagnostic
(
ErrorCode
.
ERR_InDynamicMethodArg
,
"d"
).
WithLocation
(
11
,
15
),
// (11,28): error CS8364: Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.
// M1(in d, d = 2, in d);
Diagnostic
(
ErrorCode
.
ERR_InDynamicMethodArg
,
"d"
).
WithLocation
(
11
,
28
),
// (23,15): error CS8364: Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.
// M2(in d, d = 3, in d);
Diagnostic
(
ErrorCode
.
ERR_InDynamicMethodArg
,
"d"
).
WithLocation
(
23
,
15
),
// (23,28): error CS8364: Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.
// M2(in d, d = 3, in d);
Diagnostic
(
ErrorCode
.
ERR_InDynamicMethodArg
,
"d"
).
WithLocation
(
23
,
28
)
);
}
[
WorkItem
(
22813
,
"https://github.com/dotnet/roslyn/issues/22813"
)]
[
Fact
]
public
void
InArgumentDynamicCtor
()
{
string
source
=
@"
class C
{
static void Main()
{
int x = 42;
dynamic d = 1;
var y = new M2(d, in x);
}
class M2
{
public M2(int a, in int d) => System.Console.Write(1);
public M2(int a, int d) => System.Console.Write(2);
}
}"
;
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
parseOptions
:
TestOptions
.
Regular7_2
);
comp
.
VerifyEmitDiagnostics
(
// (8,30): error CS8364: Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.
// var y = new M2(d, in x);
Diagnostic
(
ErrorCode
.
ERR_InDynamicMethodArg
,
"x"
).
WithLocation
(
8
,
30
)
);
}
[
WorkItem
(
22813
,
"https://github.com/dotnet/roslyn/issues/22813"
)]
[
Fact
]
public
void
InArgumentDynamicIndexer
()
{
string
source
=
@"
class C
{
static void Main()
{
int x = 42;
dynamic d = new C1();
System.Console.WriteLine(d[in x]);
}
class C1
{
public int this[in int x] => x;
}
}"
;
var
comp
=
CreateCompilationWithMscorlib45AndCSruntime
(
source
,
parseOptions
:
TestOptions
.
Regular7_2
);
comp
.
VerifyEmitDiagnostics
(
// (8,39): error CS8364: Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.
// System.Console.WriteLine(d[in x]);
Diagnostic
(
ErrorCode
.
ERR_InDynamicMethodArg
,
"x"
).
WithLocation
(
8
,
39
)
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录