Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET
Roslyn
提交
437dad95
R
Roslyn
项目概览
dotNET
/
Roslyn
通知
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,发现更多精彩内容 >>
提交
437dad95
编写于
9月 16, 2016
作者:
A
AlekseyTs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve location of ERR_ParamUnassigned error for local functions.
Fixes #12467.
上级
e362f8b5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
149 addition
and
5 deletion
+149
-5
src/Compilers/CSharp/Portable/FlowAnalysis/DataFlowPass.LocalFunctions.cs
...harp/Portable/FlowAnalysis/DataFlowPass.LocalFunctions.cs
+13
-3
src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
...lers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
+134
-0
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
+2
-2
未找到文件。
src/Compilers/CSharp/Portable/FlowAnalysis/DataFlowPass.LocalFunctions.cs
浏览文件 @
437dad95
...
...
@@ -111,16 +111,26 @@ public override BoundNode VisitLocalFunctionStatement(BoundLocalFunctionStatemen
RestorePending
(
oldPending2
);
// process any forward branches within the lambda body
ImmutableArray
<
PendingBranch
>
pendingReturns
=
RemoveReturns
();
RestorePending
(
oldPending
);
LeaveParameters
(
localFunc
.
Symbol
.
Parameters
,
localFunc
.
Syntax
,
null
);
Location
location
=
null
;
if
(!
localFunc
.
Symbol
.
Locations
.
IsDefaultOrEmpty
)
{
location
=
localFunc
.
Symbol
.
Locations
[
0
];
}
LeaveParameters
(
localFunc
.
Symbol
.
Parameters
,
localFunc
.
Syntax
,
location
);
LocalState
stateAtReturn
=
this
.
State
;
foreach
(
PendingBranch
pending
in
pendingReturns
)
{
this
.
State
=
pending
.
State
;
if
(
pending
.
Branch
.
Kind
==
BoundKind
.
ReturnStatement
)
BoundNode
branch
=
pending
.
Branch
;
if
(
branch
.
Kind
==
BoundKind
.
ReturnStatement
)
{
// ensure out parameters are definitely assigned at each return
LeaveParameters
(
localFunc
.
Symbol
.
Parameters
,
pending
.
Branch
.
Syntax
,
null
);
LeaveParameters
(
localFunc
.
Symbol
.
Parameters
,
branch
.
Syntax
,
branch
.
WasCompilerGenerated
?
location
:
null
);
IntersectWith
(
ref
stateAtReturn
,
ref
this
.
State
);
}
else
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
浏览文件 @
437dad95
...
...
@@ -1606,5 +1606,139 @@ async Task<async> Test(Task<async> t)
expectedOutput
:
"async"
);
}
}
[
Fact
]
[
WorkItem
(
12467
,
"https://github.com/dotnet/roslyn/issues/12467"
)]
public
void
ParamUnassigned_01
()
{
var
src
=
@"
class C
{
public void M1()
{
void TakeOutParam1(out int x)
{
}
int y;
TakeOutParam1(out y);
}
void TakeOutParam2(out int x)
{
}
}"
;
VerifyDiagnostics
(
src
,
// (6,14): error CS0177: The out parameter 'x' must be assigned to before control leaves the current method
// void TakeOutParam1(out int x)
Diagnostic
(
ErrorCode
.
ERR_ParamUnassigned
,
"TakeOutParam1"
).
WithArguments
(
"x"
).
WithLocation
(
6
,
14
),
// (14,14): error CS0177: The out parameter 'x' must be assigned to before control leaves the current method
// void TakeOutParam2(out int x)
Diagnostic
(
ErrorCode
.
ERR_ParamUnassigned
,
"TakeOutParam2"
).
WithArguments
(
"x"
).
WithLocation
(
14
,
14
)
);
}
[
Fact
]
[
WorkItem
(
12467
,
"https://github.com/dotnet/roslyn/issues/12467"
)]
public
void
ParamUnassigned_02
()
{
var
src
=
@"
class C
{
public void M1()
{
void TakeOutParam1(out int x)
{
return; // 1
}
int y;
TakeOutParam1(out y);
}
void TakeOutParam2(out int x)
{
return; // 2
}
}"
;
VerifyDiagnostics
(
src
,
// (8,13): error CS0177: The out parameter 'x' must be assigned to before control leaves the current method
// return; // 1
Diagnostic
(
ErrorCode
.
ERR_ParamUnassigned
,
"return;"
).
WithArguments
(
"x"
).
WithLocation
(
8
,
13
),
// (17,13): error CS0177: The out parameter 'x' must be assigned to before control leaves the current method
// return; // 2
Diagnostic
(
ErrorCode
.
ERR_ParamUnassigned
,
"return;"
).
WithArguments
(
"x"
).
WithLocation
(
17
,
13
)
);
}
[
Fact
]
[
WorkItem
(
12467
,
"https://github.com/dotnet/roslyn/issues/12467"
)]
public
void
ParamUnassigned_03
()
{
var
src
=
@"
class C
{
public void M1()
{
int TakeOutParam1(out int x)
{
}
int y;
TakeOutParam1(out y);
}
int TakeOutParam2(out int x)
{
}
}"
;
VerifyDiagnostics
(
src
,
// (6,13): error CS0161: 'TakeOutParam1(out int)': not all code paths return a value
// int TakeOutParam1(out int x)
Diagnostic
(
ErrorCode
.
ERR_ReturnExpected
,
"TakeOutParam1"
).
WithArguments
(
"TakeOutParam1(out int)"
).
WithLocation
(
6
,
13
),
// (6,13): error CS0177: The out parameter 'x' must be assigned to before control leaves the current method
// int TakeOutParam1(out int x)
Diagnostic
(
ErrorCode
.
ERR_ParamUnassigned
,
"TakeOutParam1"
).
WithArguments
(
"x"
).
WithLocation
(
6
,
13
),
// (14,13): error CS0177: The out parameter 'x' must be assigned to before control leaves the current method
// int TakeOutParam2(out int x)
Diagnostic
(
ErrorCode
.
ERR_ParamUnassigned
,
"TakeOutParam2"
).
WithArguments
(
"x"
).
WithLocation
(
14
,
13
),
// (14,13): error CS0161: 'C.TakeOutParam2(out int)': not all code paths return a value
// int TakeOutParam2(out int x)
Diagnostic
(
ErrorCode
.
ERR_ReturnExpected
,
"TakeOutParam2"
).
WithArguments
(
"C.TakeOutParam2(out int)"
).
WithLocation
(
14
,
13
)
);
}
[
Fact
]
[
WorkItem
(
12467
,
"https://github.com/dotnet/roslyn/issues/12467"
)]
public
void
ParamUnassigned_04
()
{
var
src
=
@"
class C
{
public void M1()
{
int TakeOutParam1(out int x)
{
return 1;
}
int y;
TakeOutParam1(out y);
}
int TakeOutParam2(out int x)
{
return 2;
}
}"
;
VerifyDiagnostics
(
src
,
// (8,13): error CS0177: The out parameter 'x' must be assigned to before control leaves the current method
// return 1;
Diagnostic
(
ErrorCode
.
ERR_ParamUnassigned
,
"return 1;"
).
WithArguments
(
"x"
).
WithLocation
(
8
,
13
),
// (17,13): error CS0177: The out parameter 'x' must be assigned to before control leaves the current method
// return 2;
Diagnostic
(
ErrorCode
.
ERR_ParamUnassigned
,
"return 2;"
).
WithArguments
(
"x"
).
WithLocation
(
17
,
13
)
);
}
}
}
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
浏览文件 @
437dad95
...
...
@@ -17751,9 +17751,9 @@ public static void Main()
// (8,23): error CS0103: The name 'x3' does not exist in the current context
// int c[out var x3] = null; // fatal syntax error - 'out' is skipped
Diagnostic(ErrorCode.ERR_NameNotInContext, "x3").WithArguments("x3").WithLocation(8, 23),
// (7,
9
): error CS0177: The out parameter 'x2' must be assigned to before control leaves the current method
// (7,
13
): error CS0177: The out parameter 'x2' must be assigned to before control leaves the current method
// int b(out var x2) = null; // parsed as a local function with syntax error
Diagnostic(ErrorCode.ERR_ParamUnassigned, "
int b(out var x2) ").WithArguments("x2").WithLocation(7, 9
),
Diagnostic(ErrorCode.ERR_ParamUnassigned, "
b").WithArguments("x2").WithLocation(7, 13
),
// (6,25): warning CS0219: The variable 'a' is assigned but its value is never used
// int[out var x1] a = null; // fatal syntax error - 'out' is skipped
Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "a").WithArguments("a").WithLocation(6, 25),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录