Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
1afc69a2
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,发现更多精彩内容 >>
提交
1afc69a2
编写于
1月 12, 2017
作者:
A
AlekseyTs
提交者:
GitHub
1月 12, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16354 from AlekseyTs/Issue12182
Improve code fix experience around constructor invocations.
上级
b0b8066e
b8b38fe0
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
118 addition
and
27 deletion
+118
-27
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
+1
-3
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs
.../Semantics/OverloadResolution/OverloadResolutionResult.cs
+7
-0
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs
...est/Emit/Attributes/AttributeTests_WellKnownAttributes.cs
+21
-18
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
+84
-1
src/Compilers/VisualBasic/Portable/Symbols/WellKnownMembers.vb
...ompilers/VisualBasic/Portable/Symbols/WellKnownMembers.vb
+1
-1
src/EditorFeatures/CSharpTest/Diagnostics/GenerateConstructor/GenerateConstructorTests.cs
...agnostics/GenerateConstructor/GenerateConstructorTests.cs
+4
-4
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
浏览文件 @
1afc69a2
...
...
@@ -4684,10 +4684,8 @@ private BoundExpression BindTypeParameterCreationExpression(ObjectCreationExpres
// CS0122: 'MyBase.MyBase' is inaccessible due to its protection level
diagnostics
.
Add
(
ErrorCode
.
ERR_BadAccess
,
errorLocation
,
result
.
ValidResult
.
Member
);
}
else
if
(!
analyzedArguments
.
HasErrors
)
else
{
// If the arguments had an error reported then do not report further errors for
// overload resolution failure.
result
.
ReportDiagnostics
(
this
,
errorLocation
,
diagnostics
,
errorName
,
null
,
analyzedArguments
,
candidateConstructors
,
typeContainingConstructors
,
null
);
}
...
...
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs
浏览文件 @
1afc69a2
...
...
@@ -894,6 +894,13 @@ private static bool HadLambdaConversionError(DiagnosticBag diagnostics, Analyzed
int
arg
)
{
BoundExpression
argument
=
arguments
.
Argument
(
arg
);
if
(
argument
.
HasAnyErrors
)
{
// If the argument had an error reported then do not report further errors for
// overload resolution failure.
return
;
}
int
parm
=
badArg
.
Result
.
ParameterFromArgument
(
arg
);
SourceLocation
sourceLocation
=
new
SourceLocation
(
argument
.
Syntax
);
...
...
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs
浏览文件 @
1afc69a2
...
...
@@ -5936,55 +5936,58 @@ public class SomeAttr1: Attribute
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
(
// (7,15): warning CS0618: 'Test.F1' is obsolete: 'F1 is obsolete'
// [SomeAttr(F1)]
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F1"
).
WithArguments
(
"Test.F1"
,
"F1 is obsolete"
),
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F1"
).
WithArguments
(
"Test.F1"
,
"F1 is obsolete"
)
.
WithLocation
(
7
,
15
)
,
// (15,15): error CS0619: 'Test.F2' is obsolete: 'F2 is obsolete'
// [SomeAttr(F2)]
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F2"
).
WithArguments
(
"Test.F2"
,
"F2 is obsolete"
),
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F2"
).
WithArguments
(
"Test.F2"
,
"F2 is obsolete"
)
.
WithLocation
(
15
,
15
)
,
// (11,15): warning CS0618: 'Test.F3' is obsolete: 'F3 is obsolete'
// [SomeAttr(F3)]
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F3"
).
WithArguments
(
"Test.F3"
,
"F3 is obsolete"
),
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F3"
).
WithArguments
(
"Test.F3"
,
"F3 is obsolete"
)
.
WithLocation
(
11
,
15
)
,
// (18,15): error CS0619: 'Test.F4' is obsolete: 'blah'
// [Obsolete(F4, true)]
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F4"
).
WithArguments
(
"Test.F4"
,
"blah"
),
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F4"
).
WithArguments
(
"Test.F4"
,
"blah"
)
.
WithLocation
(
18
,
15
)
,
// (21,15): error CS0120: An object reference is required for the non-static field, method, or property 'Test.F5'
// [Obsolete(F5)]
Diagnostic
(
ErrorCode
.
ERR_ObjectRequired
,
"F5"
).
WithArguments
(
"Test.F5"
),
Diagnostic
(
ErrorCode
.
ERR_ObjectRequired
,
"F5"
).
WithArguments
(
"Test.F5"
)
.
WithLocation
(
21
,
15
)
,
// (24,15): error CS0120: An object reference is required for the non-static field, method, or property 'Test.P1'
// [Obsolete(P1, true)]
Diagnostic
(
ErrorCode
.
ERR_ObjectRequired
,
"P1"
).
WithArguments
(
"Test.P1"
),
Diagnostic
(
ErrorCode
.
ERR_ObjectRequired
,
"P1"
).
WithArguments
(
"Test.P1"
)
.
WithLocation
(
24
,
15
)
,
// (28,15): warning CS0612: 'Test.P2' is obsolete
// [SomeAttr(P2, true)]
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbol
,
"P2"
).
WithArguments
(
"Test.P2"
),
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbol
,
"P2"
).
WithArguments
(
"Test.P2"
)
.
WithLocation
(
28
,
15
)
,
// (28,15): error CS0120: An object reference is required for the non-static field, method, or property 'Test.P2'
// [SomeAttr(P2, true)]
Diagnostic
(
ErrorCode
.
ERR_ObjectRequired
,
"P2"
).
WithArguments
(
"Test.P2"
),
Diagnostic
(
ErrorCode
.
ERR_ObjectRequired
,
"P2"
).
WithArguments
(
"Test.P2"
).
WithLocation
(
28
,
15
),
// (28,6): error CS1729: 'SomeAttr' does not contain a constructor that takes 2 arguments
// [SomeAttr(P2, true)]
Diagnostic
(
ErrorCode
.
ERR_BadCtorArgCount
,
"SomeAttr(P2, true)"
).
WithArguments
(
"SomeAttr"
,
"2"
).
WithLocation
(
28
,
6
),
// (31,15): error CS1503: Argument 1: cannot convert from 'method group' to 'string'
// [Obsolete(Method1)]
Diagnostic
(
ErrorCode
.
ERR_BadArgType
,
"Method1"
).
WithArguments
(
"1"
,
"method group"
,
"string"
),
Diagnostic
(
ErrorCode
.
ERR_BadArgType
,
"Method1"
).
WithArguments
(
"1"
,
"method group"
,
"string"
)
.
WithLocation
(
31
,
15
)
,
// (35,16): warning CS0612: 'Test.Method2()' is obsolete
// [SomeAttr1(Method2)]
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbol
,
"Method2"
).
WithArguments
(
"Test.Method2()"
),
// (35,6): error CS0181: Attribute constructor parameter 'x' has type '
System.
Action', which is not a valid attribute parameter type
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbol
,
"Method2"
).
WithArguments
(
"Test.Method2()"
)
.
WithLocation
(
35
,
16
)
,
// (35,6): error CS0181: Attribute constructor parameter 'x' has type 'Action', which is not a valid attribute parameter type
// [SomeAttr1(Method2)]
Diagnostic
(
ErrorCode
.
ERR_BadAttributeParamType
,
"SomeAttr1"
).
WithArguments
(
"x"
,
"System.Action"
),
Diagnostic
(
ErrorCode
.
ERR_BadAttributeParamType
,
"SomeAttr1"
).
WithArguments
(
"x"
,
"System.Action"
)
.
WithLocation
(
35
,
6
)
,
// (43,15): error CS0619: 'Test.F7' is obsolete: 'F7 is obsolete'
// [Obsolete(F7, true)]
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F7"
).
WithArguments
(
"Test.F7"
,
"F7 is obsolete"
),
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F7"
).
WithArguments
(
"Test.F7"
,
"F7 is obsolete"
)
.
WithLocation
(
43
,
15
)
,
// (44,15): warning CS0618: 'Test.F6' is obsolete: 'F6 is obsolete'
// [SomeAttr(F6)]
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F6"
).
WithArguments
(
"Test.F6"
,
"F6 is obsolete"
),
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F6"
).
WithArguments
(
"Test.F6"
,
"F6 is obsolete"
)
.
WithLocation
(
44
,
15
)
,
// (45,15): error CS0619: 'Test.F7' is obsolete: 'F7 is obsolete'
// [SomeAttr(F7)]
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F7"
).
WithArguments
(
"Test.F7"
,
"F7 is obsolete"
),
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F7"
).
WithArguments
(
"Test.F7"
,
"F7 is obsolete"
)
.
WithLocation
(
45
,
15
)
,
// (38,15): warning CS0618: 'Test.F6' is obsolete: 'F6 is obsolete'
// [Obsolete(F6)]
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F6"
).
WithArguments
(
"Test.F6"
,
"F6 is obsolete"
),
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F6"
).
WithArguments
(
"Test.F6"
,
"F6 is obsolete"
)
.
WithLocation
(
38
,
15
)
,
// (39,15): warning CS0618: 'Test.F6' is obsolete: 'F6 is obsolete'
// [SomeAttr(F6)]
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F6"
).
WithArguments
(
"Test.F6"
,
"F6 is obsolete"
),
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbolStr
,
"F6"
).
WithArguments
(
"Test.F6"
,
"F6 is obsolete"
)
.
WithLocation
(
39
,
15
)
,
// (40,15): error CS0619: 'Test.F7' is obsolete: 'F7 is obsolete'
// [SomeAttr(F7)]
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F7"
).
WithArguments
(
"Test.F7"
,
"F7 is obsolete"
));
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"F7"
).
WithArguments
(
"Test.F7"
,
"F7 is obsolete"
)
.
WithLocation
(
40
,
15
)
);
}
[
WorkItem
(
546064
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546064"
)]
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
浏览文件 @
1afc69a2
...
...
@@ -54,6 +54,77 @@ static void Test2(object x, int y)
VerifyModelForOutVar(model, x1Decl, x1Ref);
}
[Fact]
[WorkItem(12182, "https://github.com/dotnet/roslyn/issues/12182")]
[WorkItem(16348, "https://github.com/dotnet/roslyn/issues/16348")]
public void DiagnosticsDifferenceBetweenLanguageVersions_01()
{
var text = @"
public class Cls
{
public static void Test1()
{
Test(out int x1);
}
public static void Test2()
{
var x = new Cls(out int x2);
}
}";
var compilation = CreateCompilationWithMscorlib(text, options: TestOptions.ReleaseDll, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp6));
compilation.VerifyDiagnostics(
// (6,22): error CS8059: Feature 'out variable declaration' is not available in C# 6. Please use language version 7 or greater.
// Test(out int x1);
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion6, "x1").WithArguments("out variable declaration", "7").WithLocation(6, 22),
// (11,33): error CS8059: Feature 'out variable declaration' is not available in C# 6. Please use language version 7 or greater.
// var x = new Cls(out int x2);
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion6, "x2").WithArguments("out variable declaration", "7").WithLocation(11, 33),
// (6,9): error CS0103: The name 'Test' does not exist in the current context
// Test(out int x1);
Diagnostic(ErrorCode.ERR_NameNotInContext, "Test").WithArguments("Test").WithLocation(6, 9),
// (11,21): error CS1729: 'Cls' does not contain a constructor that takes 1 arguments
// var x = new Cls(out int x2);
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Cls").WithArguments("Cls", "1").WithLocation(11, 21),
// (11,29): error CS0165: Use of unassigned local variable 'x2'
// var x = new Cls(out int x2);
Diagnostic(ErrorCode.ERR_UseDefViolation, "int x2").WithArguments("x2").WithLocation(11, 29)
);
var tree = compilation.SyntaxTrees.Single();
var model = compilation.GetSemanticModel(tree);
var x1Decl = GetOutVarDeclaration(tree, "x1");
VerifyModelForOutVar(model, x1Decl);
var x2Decl = GetOutVarDeclaration(tree, "x2");
//VerifyModelForOutVar(model, x2Decl); Probably fails due to https://github.com/dotnet/roslyn/issues/16348
VerifyModelForOutVarWithoutDataFlow(model, x2Decl);
compilation = CreateCompilationWithMscorlib(text, options: TestOptions.ReleaseDll, parseOptions: TestOptions.Regular);
compilation.VerifyDiagnostics(
// (6,9): error CS0103: The name 'Test' does not exist in the current context
// Test(out int x1);
Diagnostic(ErrorCode.ERR_NameNotInContext, "Test").WithArguments("Test").WithLocation(6, 9),
// (11,21): error CS1729: 'Cls' does not contain a constructor that takes 1 arguments
// var x = new Cls(out int x2);
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Cls").WithArguments("Cls", "1").WithLocation(11, 21),
// (11,29): error CS0165: Use of unassigned local variable 'x2'
// var x = new Cls(out int x2);
Diagnostic(ErrorCode.ERR_UseDefViolation, "int x2").WithArguments("x2").WithLocation(11, 29)
);
tree = compilation.SyntaxTrees.Single();
model = compilation.GetSemanticModel(tree);
x1Decl = GetOutVarDeclaration(tree, "x1");
VerifyModelForOutVar(model, x1Decl);
x2Decl = GetOutVarDeclaration(tree, "x2");
//VerifyModelForOutVar(model, x2Decl); Probably fails due to https://github.com/dotnet/roslyn/issues/16348
VerifyModelForOutVarWithoutDataFlow(model, x2Decl);
}
[Fact]
[CompilerTrait(CompilerFeature.Tuples)]
[WorkItem(13148, "https://github.com/dotnet/roslyn/issues/13148")]
...
...
@@ -2296,9 +2367,15 @@ class Test : System.Attribute
// (4,19): error CS0103: The name 'x3' does not exist in the current context
// [Test(out var x3)]
Diagnostic(ErrorCode.ERR_NameNotInContext, "x3").WithArguments("x3").WithLocation(4, 19),
// (4,6): error CS1729: 'Test' does not contain a constructor that takes 2 arguments
// [Test(out var x3)]
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Test(out var x3)").WithArguments("Test", "2").WithLocation(4, 6),
// (5,19): error CS0103: The name 'x4' does not exist in the current context
// [Test(out int x4)]
Diagnostic(ErrorCode.ERR_NameNotInContext, "x4").WithArguments("x4").WithLocation(5, 19),
// (5,6): error CS1729: 'Test' does not contain a constructor that takes 2 arguments
// [Test(out int x4)]
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Test(out int x4)").WithArguments("Test", "2").WithLocation(5, 6),
// (6,18): error CS0103: The name 'var' does not exist in the current context
// [Test(p: out var x5)]
Diagnostic(ErrorCode.ERR_NameNotInContext, "var").WithArguments("var").WithLocation(6, 18),
...
...
@@ -2308,12 +2385,18 @@ class Test : System.Attribute
// (6,22): error CS0103: The name 'x5' does not exist in the current context
// [Test(p: out var x5)]
Diagnostic(ErrorCode.ERR_NameNotInContext, "x5").WithArguments("x5").WithLocation(6, 22),
// (6,6): error CS1729: 'Test' does not contain a constructor that takes 3 arguments
// [Test(p: out var x5)]
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Test(p: out var x5)").WithArguments("Test", "3").WithLocation(6, 6),
// (7,18): error CS1738: Named argument specifications must appear after all fixed arguments have been specified
// [Test(p: out int x6)]
Diagnostic(ErrorCode.ERR_NamedArgumentSpecificationBeforeFixedArgument, "int").WithLocation(7, 18),
// (7,22): error CS0103: The name 'x6' does not exist in the current context
// [Test(p: out int x6)]
Diagnostic(ErrorCode.ERR_NameNotInContext, "x6").WithArguments("x6").WithLocation(7, 22)
Diagnostic(ErrorCode.ERR_NameNotInContext, "x6").WithArguments("x6").WithLocation(7, 22),
// (7,6): error CS1729: 'Test' does not contain a constructor that takes 3 arguments
// [Test(p: out int x6)]
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Test(p: out int x6)").WithArguments("Test", "3").WithLocation(7, 6)
);
var tree = compilation.SyntaxTrees.Single();
src/Compilers/VisualBasic/Portable/Symbols/WellKnownMembers.vb
浏览文件 @
1afc69a2
...
...
@@ -177,7 +177,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
New
SynthesizedAttributeData
(
constructorSymbol
,
arguments
,
namedStringArguments
)
End
Function
Private
Function
ReturnNothingOrThrowIfAttributeNonOptional
(
constructor
As
WellKnownMember
,
Optional
isOptionalUse
As
Boolean
=
False
)
As
SynthesizedAttributeData
Private
Shared
Function
ReturnNothingOrThrowIfAttributeNonOptional
(
constructor
As
WellKnownMember
,
Optional
isOptionalUse
As
Boolean
=
False
)
As
SynthesizedAttributeData
If
isOptionalUse
OrElse
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
constructor
)
Then
Return
Nothing
Else
...
...
src/EditorFeatures/CSharpTest/Diagnostics/GenerateConstructor/GenerateConstructorTests.cs
浏览文件 @
1afc69a2
...
...
@@ -2978,7 +2978,7 @@ void M()
withScriptOption
:
true
);
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/12182"
)
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateConstructor
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateConstructor
)]
[
WorkItem
(
12182
,
"https://github.com/dotnet/roslyn/issues/12182"
)]
public
async
Task
TestOutVariableDeclaration_ImplicitlyTyped_CSharp6
()
{
...
...
@@ -3006,7 +3006,7 @@ void M()
withScriptOption
:
true
);
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/12182"
)
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateConstructor
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateConstructor
)]
[
WorkItem
(
12182
,
"https://github.com/dotnet/roslyn/issues/12182"
)]
public
async
Task
TestOutVariableDeclaration_ImplicitlyTyped_NamedArgument_CSharp6
()
{
...
...
@@ -3034,7 +3034,7 @@ void M()
withScriptOption
:
true
);
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/12182"
)
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateConstructor
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateConstructor
)]
[
WorkItem
(
12182
,
"https://github.com/dotnet/roslyn/issues/12182"
)]
public
async
Task
TestOutVariableDeclaration_ExplicitlyTyped_CSharp6
()
{
...
...
@@ -3062,7 +3062,7 @@ void M()
withScriptOption
:
true
);
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/12182"
)
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateConstructor
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateConstructor
)]
[
WorkItem
(
12182
,
"https://github.com/dotnet/roslyn/issues/12182"
)]
public
async
Task
TestOutVariableDeclaration_ExplicitlyTyped_NamedArgument_CSharp6
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录