Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
07e1b309
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,发现更多精彩内容 >>
提交
07e1b309
编写于
2月 11, 2017
作者:
A
AlekseyTs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow expression variables in lambdas within constructor and field initializers.
Fixes #16935.
上级
2c505555
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
223 addition
and
4 deletion
+223
-4
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
+1
-1
src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
+1
-1
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
+117
-1
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
...rs/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
+103
-0
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_Global.cs
...rp/Test/Semantic/Semantics/PatternMatchingTests_Global.cs
+1
-1
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
浏览文件 @
07e1b309
...
...
@@ -2200,7 +2200,7 @@ private BoundExpression BindOutVariableArgument(DeclarationExpressionSyntax decl
SourceLocalSymbol
localSymbol
=
this
.
LookupLocal
(
designation
.
Identifier
);
if
((
object
)
localSymbol
!=
null
)
{
if
(
InConstructorInitializer
||
InFieldInitializer
)
if
(
(
InConstructorInitializer
||
InFieldInitializer
)
&&
ContainingMemberOrLambda
.
ContainingSymbol
.
Kind
==
SymbolKind
.
NamedType
)
{
Error
(
diagnostics
,
ErrorCode
.
ERR_ExpressionVariableInConstructorOrFieldInitializer
,
declarationExpression
);
}
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
浏览文件 @
07e1b309
...
...
@@ -292,7 +292,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
if
(
localSymbol
!=
(
object
)
null
)
{
if
(
InConstructorInitializer
||
InFieldInitializer
)
if
(
(
InConstructorInitializer
||
InFieldInitializer
)
&&
ContainingMemberOrLambda
.
ContainingSymbol
.
Kind
==
SymbolKind
.
NamedType
)
{
Error
(
diagnostics
,
ErrorCode
.
ERR_ExpressionVariableInConstructorOrFieldInitializer
,
node
);
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
浏览文件 @
07e1b309
...
...
@@ -5273,6 +5273,39 @@ static bool TakeOutParam(int y, out int x)
#endif
}
[Fact]
[WorkItem(16935, "https://github.com/dotnet/roslyn/issues/16935")]
public void FieldInitializers_04()
{
var source =
@"
public class X
{
public static void Main()
{
System.Console.WriteLine(Test1());
}
static System.Func<bool> Test1 = () => TakeOutParam(1, out int x1) && Dummy(x1);
static bool Dummy(int x)
{
System.Console.WriteLine(x);
return true;
}
static bool TakeOutParam(int y, out int x)
{
x = y;
return true;
}
}
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular);
CompileAndVerify(compilation, expectedOutput: @"1
True");
}
[Fact]
public void Scope_Fixed_01()
{
...
...
@@ -10688,6 +10721,39 @@ static bool TakeOutParam(int y, out int x)
#endif
}
[Fact]
[WorkItem(16935, "https://github.com/dotnet/roslyn/issues/16935")]
public void PropertyInitializers_02()
{
var source =
@"
public class X
{
public static void Main()
{
System.Console.WriteLine(Test1());
}
static System.Func<bool> Test1 {get;} = () => TakeOutParam(1, out int x1) && Dummy(x1);
static bool Dummy(int x)
{
System.Console.WriteLine(x);
return true;
}
static bool TakeOutParam(int y, out int x)
{
x = y;
return true;
}
}
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular);
CompileAndVerify(compilation, expectedOutput: @"1
True");
}
[Fact]
public void Scope_Query_01()
{
...
...
@@ -17720,6 +17786,56 @@ class Test3 : Test2
VerifyModelForOutVar(model, x1Decl);
}
[Fact]
[WorkItem(16935, "https://github.com/dotnet/roslyn/issues/16935")]
public void ConstructorInitializers_05()
{
var text = @"
public class Cls
{
public static void Main()
{
Do(new Test2());
}
static void Do(object x){}
public static object Test1(out int x)
{
x = 123;
return null;
}
class Test2
{
Test2(System.Func<object> x)
{
System.Console.WriteLine(x());
}
public Test2()
: this(() =>
{
Test1(out var x1);
return x1;
})
{}
}
}";
var compilation = CreateCompilationWithMscorlib(text,
options: TestOptions.ReleaseExe,
parseOptions: TestOptions.Regular);
CompileAndVerify(compilation, expectedOutput: @"123").VerifyDiagnostics();
var tree = compilation.SyntaxTrees.Single();
var model = compilation.GetSemanticModel(tree);
var x1Decl = GetOutVarDeclaration(tree, "x1");
var x1Ref = GetReference(tree, "x1");
VerifyModelForOutVar(model, x1Decl, x1Ref);
}
[Fact]
public void SimpleVar_14()
{
...
...
@@ -22658,7 +22774,7 @@ static bool TakeOutParam(bool y, out bool x)
}
}
[Fact
(Skip = "https://github.com/dotnet/roslyn/issues/16935")
]
[Fact]
[WorkItem(16935, "https://github.com/dotnet/roslyn/issues/16935")]
public void GlobalCode_Lambda_02()
{
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
浏览文件 @
07e1b309
...
...
@@ -1088,6 +1088,33 @@ static bool Dummy(System.Func<int> x)
#endif
}
[
Fact
]
[
WorkItem
(
16935
,
"https://github.com/dotnet/roslyn/issues/16935"
)]
public
void
FieldInitializers_04
()
{
var
source
=
@"
public class X
{
public static void Main()
{
System.Console.WriteLine(Test1());
}
static System.Func<bool> Test1 = () => 1 is int x1 && Dummy(x1);
static bool Dummy(int x)
{
System.Console.WriteLine(x);
return true;
}
}
"
;
var
compilation
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugExe
);
CompileAndVerify
(
compilation
,
expectedOutput
:
@"1
True"
);
}
[
Fact
]
public
void
PropertyInitializers_01
()
{
...
...
@@ -1121,6 +1148,34 @@ static bool Dummy(int x)
);
#endif
}
[
Fact
]
[
WorkItem
(
16935
,
"https://github.com/dotnet/roslyn/issues/16935"
)]
public
void
PropertyInitializers_02
()
{
var
source
=
@"
public class X
{
public static void Main()
{
System.Console.WriteLine(Test1());
}
static System.Func<bool> Test1 {get;} = () => 1 is int x1 && Dummy(x1);
static bool Dummy(int x)
{
System.Console.WriteLine(x);
return true;
}
}
"
;
var
compilation
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugExe
);
CompileAndVerify
(
compilation
,
expectedOutput
:
@"1
True"
);
}
[
Fact
]
public
void
ConstructorInitializers_01
()
{
...
...
@@ -1179,6 +1234,54 @@ public C(object b)
#endif
}
[
Fact
]
[
WorkItem
(
16935
,
"https://github.com/dotnet/roslyn/issues/16935"
)]
public
void
ConstructorInitializers_02
()
{
var
source
=
@"
public class X
{
public static void Main()
{
var x = new D();
}
}
class D : C
{
public D(System.Func<bool> o) : base(() => 2 is int x1 && Dummy(x1))
{
System.Console.WriteLine(o());
}
public D() : this(() => 1 is int x1 && Dummy(x1))
{
}
static bool Dummy(int x)
{
System.Console.WriteLine(x);
return true;
}
}
class C
{
public C(System.Func<bool> b)
{
System.Console.WriteLine(b());
}
}
"
;
var
compilation
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugExe
);
CompileAndVerify
(
compilation
,
expectedOutput
:
@"2
True
1
True"
);
}
[
Fact
]
public
void
Switch_01
()
{
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_Global.cs
浏览文件 @
07e1b309
...
...
@@ -7196,7 +7196,7 @@ public void GlobalCode_Lambda_01()
}
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/16935"
)
]
[
Fact
]
[
WorkItem
(
16935
,
"https://github.com/dotnet/roslyn/issues/16935"
)]
public
void
GlobalCode_Lambda_02
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录