Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
7e7ea6a9
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,发现更多精彩内容 >>
提交
7e7ea6a9
编写于
3月 16, 2017
作者:
V
vsadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rebased onto the recent merge from master
上级
4e84ece8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
15 deletion
+43
-15
src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
+14
-6
src/Compilers/CSharp/Portable/CodeGen/EmitExpression.cs
src/Compilers/CSharp/Portable/CodeGen/EmitExpression.cs
+3
-1
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReturnTests.cs
...mpilers/CSharp/Test/Emit/CodeGen/CodeGenRefReturnTests.cs
+26
-8
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
浏览文件 @
7e7ea6a9
...
...
@@ -173,7 +173,7 @@ private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind
return
expr
;
case
BoundKind
.
DiscardExpression
:
Debug
.
Assert
(
valueKind
==
BindValueKind
.
Assignable
||
valueKind
==
BindValueKind
.
RefOrOut
);
Debug
.
Assert
(
valueKind
==
BindValueKind
.
Assignable
||
valueKind
==
BindValueKind
.
RefOrOut
||
diagnostics
.
HasAnyResolvedErrors
()
);
return
expr
;
}
...
...
@@ -274,11 +274,6 @@ internal bool CheckValueKind(SyntaxNode node, BoundExpression expr, BindValueKin
case
BoundKind
.
EventAccess
:
return
CheckEventValueKind
((
BoundEventAccess
)
expr
,
valueKind
,
diagnostics
);
//PROTOTYPE(readonlyeRefs): this is incorrect and fixed in master. Update when merged.
case
BoundKind
.
DynamicMemberAccess
:
case
BoundKind
.
DynamicIndexerAccess
:
return
true
;
}
// easy out for a very common RValue case.
...
...
@@ -350,6 +345,19 @@ internal bool CheckValueKind(SyntaxNode node, BoundExpression expr, BindValueKin
}
break
;
case
BoundKind
.
DynamicMemberAccess
:
case
BoundKind
.
DynamicIndexerAccess
:
// dynamic expressions can be read and written to
// can even be passed by reference (which is implemented via a temp)
// it is not valid to return them by reference though.
if
(
RequiresReturnableReference
(
valueKind
))
{
Error
(
diagnostics
,
ErrorCode
.
ERR_RefReturnLvalueExpected
,
expr
.
Syntax
);
return
false
;
}
return
true
;
case
BoundKind
.
Parameter
:
var
parameter
=
(
BoundParameter
)
expr
;
return
CheckParameterValueKind
(
node
,
parameter
,
valueKind
,
checkingReceiver
,
diagnostics
);
...
...
src/Compilers/CSharp/Portable/CodeGen/EmitExpression.cs
浏览文件 @
7e7ea6a9
...
...
@@ -582,7 +582,9 @@ private void EmitArgument(BoundExpression argument, RefKind refKind)
else
{
var
temp
=
EmitAddress
(
argument
,
AddressKind
.
Writeable
);
Debug
.
Assert
(
temp
==
null
,
"passing args byref should not clone them into temps"
);
// Dynamic is allowed to be passed by reference, via a temp.
Debug
.
Assert
(
temp
==
null
||
argument
.
Type
.
IsDynamic
(),
"passing args byref should not clone them into temps"
);
}
}
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReturnTests.cs
浏览文件 @
7e7ea6a9
...
...
@@ -2836,6 +2836,7 @@ static void Main()
);
}
[
Fact
]
[
WorkItem
(
16947
,
"https://github.com/dotnet/roslyn/issues/16947"
)]
public
void
Dynamic001
()
{
...
...
@@ -2853,18 +2854,28 @@ public void M()
public static ref dynamic F(ref dynamic d)
{
// this is ok
F1(ref d.Length);
// this is an error
return ref d.Length;
}
public static void F1(ref dynamic d)
{
}
}
"
;
CreateCompilationWithMscorlib45AndCSruntime
(
source
).
VerifyEmitDiagnostics
(
// (1
4
,20): error CS8156: An expression cannot be used in this context because it may not be returned by reference
// (1
8
,20): error CS8156: An expression cannot be used in this context because it may not be returned by reference
// return ref d.Length;
Diagnostic
(
ErrorCode
.
ERR_RefReturnLvalueExpected
,
"d.Length"
).
WithLocation
(
1
4
,
20
)
Diagnostic
(
ErrorCode
.
ERR_RefReturnLvalueExpected
,
"d.Length"
).
WithLocation
(
1
8
,
20
)
);
}
[
Fact
]
[
WorkItem
(
16947
,
"https://github.com/dotnet/roslyn/issues/16947"
)]
public
void
Dynamic002
()
{
...
...
@@ -2882,19 +2893,27 @@ public void M()
public static ref dynamic F(ref dynamic d)
{
// this is ok
F1(ref d[0]);
return ref d[0];
}
public static void F1(ref dynamic d)
{
}
}
"
;
CreateCompilationWithMscorlib45AndCSruntime
(
source
).
VerifyEmitDiagnostics
(
// (1
4
,20): error CS8156: An expression cannot be used in this context because it may not be returned by reference
// (1
7
,20): error CS8156: An expression cannot be used in this context because it may not be returned by reference
// return ref d[0];
Diagnostic
(
ErrorCode
.
ERR_RefReturnLvalueExpected
,
"d[0]"
).
WithLocation
(
1
4
,
20
)
Diagnostic
(
ErrorCode
.
ERR_RefReturnLvalueExpected
,
"d[0]"
).
WithLocation
(
1
7
,
20
)
);
}
[
Fact
]
[
WorkItem
(
16947
,
"https://github.com/dotnet/roslyn/issues/16947"
)]
public
void
Dynamic003
()
{
...
...
@@ -2924,13 +2943,12 @@ public void M()
"
;
CreateCompilationWithMscorlib45AndCSruntime
(
source
).
VerifyEmitDiagnostics
(
// (14,2
8
): error CS8156: An expression cannot be used in this context because it may not be returned by reference
// (14,2
6
): error CS8156: An expression cannot be used in this context because it may not be returned by reference
// return ref G(ref d.Length);
Diagnostic
(
ErrorCode
.
ERR_RefReturnLvalueExpected
,
"d.Length"
).
WithLocation
(
14
,
2
8
),
Diagnostic
(
ErrorCode
.
ERR_RefReturnLvalueExpected
,
"d.Length"
).
WithLocation
(
14
,
2
6
),
// (14,20): error CS8164: Cannot return by reference a result of 'C.G(ref dynamic)' because the argument passed to parameter 'd' cannot be returned by reference
// return ref G(ref d.Length);
Diagnostic
(
ErrorCode
.
ERR_RefReturnCall
,
"G(ref d.Length)"
).
WithArguments
(
"C.G(ref dynamic)"
,
"d"
).
WithLocation
(
14
,
20
)
Diagnostic
(
ErrorCode
.
ERR_RefReturnCall
,
"G(ref d.Length)"
).
WithArguments
(
"C.G(ref dynamic)"
,
"d"
)
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录