Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
bb0ff321
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,发现更多精彩内容 >>
提交
bb0ff321
编写于
1月 12, 2016
作者:
V
VSadov
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7718 from VSadov/fix6416
Make captured "this" a constant in expression trees.
上级
4e879317
94cdb05c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
172 addition
and
2 deletion
+172
-2
src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs
...table/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs
+6
-1
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs
...pilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs
+111
-0
src/Compilers/VisualBasic/Portable/Lowering/ExpressionLambdaRewriter/ExpressionLambdaRewriter.vb
...ring/ExpressionLambdaRewriter/ExpressionLambdaRewriter.vb
+5
-1
src/Compilers/VisualBasic/Test/Emit/ExpressionTrees/CodeGenExprLambda.vb
...isualBasic/Test/Emit/ExpressionTrees/CodeGenExprLambda.vb
+50
-0
未找到文件。
src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs
浏览文件 @
bb0ff321
...
@@ -202,7 +202,12 @@ private BoundExpression VisitExpressionWithoutStackGuard(BoundExpression node)
...
@@ -202,7 +202,12 @@ private BoundExpression VisitExpressionWithoutStackGuard(BoundExpression node)
case
BoundKind
.
DelegateCreationExpression
:
case
BoundKind
.
DelegateCreationExpression
:
return
VisitDelegateCreationExpression
((
BoundDelegateCreationExpression
)
node
);
return
VisitDelegateCreationExpression
((
BoundDelegateCreationExpression
)
node
);
case
BoundKind
.
FieldAccess
:
case
BoundKind
.
FieldAccess
:
return
VisitFieldAccess
((
BoundFieldAccess
)
node
);
var
fieldAccess
=
(
BoundFieldAccess
)
node
;
if
(
fieldAccess
.
FieldSymbol
.
IsCapturedFrame
)
{
return
Constant
(
fieldAccess
);
}
return
VisitFieldAccess
(
fieldAccess
);
case
BoundKind
.
IsOperator
:
case
BoundKind
.
IsOperator
:
return
VisitIsOperator
((
BoundIsOperator
)
node
);
return
VisitIsOperator
((
BoundIsOperator
)
node
);
case
BoundKind
.
Lambda
:
case
BoundKind
.
Lambda
:
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenExprLambdaTests.cs
浏览文件 @
bb0ff321
...
@@ -5899,6 +5899,117 @@ static int foo(int x)
...
@@ -5899,6 +5899,117 @@ static int foo(int x)
expectedOutput
:
expectedOutput
);
expectedOutput
:
expectedOutput
);
}
}
[
WorkItem
(
6416
,
"https://github.com/dotnet/roslyn/issues/6416"
)]
[
Fact
]
public
void
CapturedThis001
()
{
const
string
source
=
@"
using System;
using System.Linq.Expressions;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
var v = new Program();
v.test();
}
public int P1
{
get
{
return 42;
}
}
public void test()
{
var local = 0;
Func<Expression<Func<int>>> f =
() =>
{
System.Console.WriteLine(P1 + local);
return () => P1;
};
System.Console.WriteLine((f().Body as MemberExpression).Expression);
}
}
}
"
;
const
string
expectedOutput
=
@"42
value(ConsoleApplication6.Program)"
;
CompileAndVerify
(
new
[]
{
source
,
},
new
[]
{
ExpressionAssemblyRef
},
expectedOutput
:
expectedOutput
);
}
[
WorkItem
(
6416
,
"https://github.com/dotnet/roslyn/issues/6416"
)]
[
Fact
]
public
void
CapturedThis002
()
{
const
string
source
=
@"
using System;
using System.Linq.Expressions;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
var v = new Program();
v.test();
}
public int P1
{
get
{
return 42;
}
}
public void test()
{
var local = 0;
Func<Expression<Func<Expression<Func<int>>>>> ff = () =>
{
Func<Expression<Func<int>>> f =
() =>
{
System.Console.WriteLine(P1 + local);
return () => P1;
};
return () => f();
};
System.Console.WriteLine((ff().Compile()().Body as MemberExpression).Expression);
}
}
}
"
;
const
string
expectedOutput
=
@"42
value(ConsoleApplication6.Program)"
;
CompileAndVerify
(
new
[]
{
source
,
},
new
[]
{
ExpressionAssemblyRef
},
expectedOutput
:
expectedOutput
);
}
#
endregion
Regression
Tests
#
endregion
Regression
Tests
...
...
src/Compilers/VisualBasic/Portable/Lowering/ExpressionLambdaRewriter/ExpressionLambdaRewriter.vb
浏览文件 @
bb0ff321
...
@@ -217,7 +217,11 @@ lSelect:
...
@@ -217,7 +217,11 @@ lSelect:
Case
BoundKind
.
DirectCast
Case
BoundKind
.
DirectCast
Return
VisitDirectCast
(
DirectCast
(
node
,
BoundDirectCast
))
Return
VisitDirectCast
(
DirectCast
(
node
,
BoundDirectCast
))
Case
BoundKind
.
FieldAccess
Case
BoundKind
.
FieldAccess
Return
VisitFieldAccess
(
DirectCast
(
node
,
BoundFieldAccess
))
Dim
fieldAccess
=
DirectCast
(
node
,
BoundFieldAccess
)
If
fieldAccess
.
FieldSymbol
.
IsCapturedFrame
Then
Return
CreateLiteralExpression
(
node
)
End
If
Return
VisitFieldAccess
(
fieldAccess
)
Case
BoundKind
.
Lambda
Case
BoundKind
.
Lambda
Return
VisitLambda
(
DirectCast
(
node
,
BoundLambda
))
Return
VisitLambda
(
DirectCast
(
node
,
BoundLambda
))
Case
BoundKind
.
NewT
Case
BoundKind
.
NewT
...
...
src/Compilers/VisualBasic/Test/Emit/ExpressionTrees/CodeGenExprLambda.vb
浏览文件 @
bb0ff321
...
@@ -8198,5 +8198,55 @@ End Module
...
@@ -8198,5 +8198,55 @@ End Module
End
Sub
End
Sub
<
Fact
,
WorkItem
(
6416
,
"https://github.com/dotnet/roslyn/issues/6416"
)
>
Public
Sub
CapturedMe001
()
Dim
source
=
<
compilation
>
<
file
name
=
"a.vb"
><
!
[
CDATA
[
Imports
System
Imports
System.Linq.Expressions
Class
Module1
Public
Shared
Sub
Main
()
Dim
v
=
New
Module1
()
v
.
test
()
End
Sub
Public
ReadOnly
Property
P1
As
Integer
Get
Return
42
End
Get
End
Property
Public
Sub
test
()
Dim
local
=
0
Dim
f
As
Func
(
Of
Expression
(
Of
Func
(
Of
Integer
)))
=
Function
()
System
.
Console
.
WriteLine
(
P1
+
local
)
Return
Function
()
P1
End
Function
System
.
Console
.
WriteLine
(
DirectCast
(
f
().
Body
,
MemberExpression
).
Expression
)
End
Sub
End
Class
]]
></
file
>
</
compilation
>
CompileAndVerify
(
source
,
additionalRefs
:
=
{
SystemCoreRef
},
options
:
=
TestOptions
.
ReleaseExe
,
expectedOutput
:
=<
!
[
CDATA
[
42
value
(
Module1
)
]]
>
).
VerifyDiagnostics
()
End
Sub
End
Class
End
Class
End
Namespace
End
Namespace
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录