Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
674f4e1c
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,发现更多精彩内容 >>
提交
674f4e1c
编写于
9月 06, 2017
作者:
J
Julien Couvreur
提交者:
GitHub
9月 06, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Complete goto default; without extra colon (#21861)
上级
042a8a5a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
206 addition
and
23 deletion
+206
-23
src/Compilers/CSharp/Portable/Symbols/Source/SourceLabelSymbol.cs
...ilers/CSharp/Portable/Symbols/Source/SourceLabelSymbol.cs
+5
-0
src/Compilers/CSharp/Test/Semantic/Semantics/LookupPositionTests.cs
...ers/CSharp/Test/Semantic/Semantics/LookupPositionTests.cs
+28
-0
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
...rs/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
+2
-2
src/Compilers/CSharp/Test/Semantic/Semantics/SwitchTests.cs
src/Compilers/CSharp/Test/Semantic/Semantics/SwitchTests.cs
+50
-18
src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs
...bol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs
+1
-1
src/Compilers/CSharp/Test/Symbol/Symbols/Source/DeclaringSyntaxNodeTests.cs
...rp/Test/Symbol/Symbols/Source/DeclaringSyntaxNodeTests.cs
+1
-1
src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs
...tion/CompletionProviders/SymbolCompletionProviderTests.cs
+1
-1
src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb
...Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb
+112
-0
src/Features/CSharp/Portable/Completion/CompletionProviders/CompletionUtilities.cs
...ble/Completion/CompletionProviders/CompletionUtilities.cs
+6
-0
未找到文件。
src/Compilers/CSharp/Portable/Symbols/Source/SourceLabelSymbol.cs
浏览文件 @
674f4e1c
...
...
@@ -44,6 +44,11 @@ private string MakeLabelName()
var
node
=
_identifierNodeOrToken
.
AsNode
();
if
(
node
!=
null
)
{
if
(
node
.
Kind
()
==
SyntaxKind
.
DefaultSwitchLabel
)
{
return
((
DefaultSwitchLabelSyntax
)
node
).
Keyword
.
ToString
();
}
return
node
.
ToString
();
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/LookupPositionTests.cs
浏览文件 @
674f4e1c
...
...
@@ -1468,6 +1468,34 @@ static void Main(string[] args)
Assert
.
True
(
symbols
.
IsEmpty
);
}
[
Fact
]
public
void
GotoLabelShouldNotHaveColon
()
{
var
source
=
@"
class Program
{
static void M(object o)
{
switch (o)
{
case int i:
goto HERE;
default:
@default:
label1:
break;
}
}
}
"
;
var
compilation
=
CreateStandardCompilation
(
source
);
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
var
symbols
=
model
.
LookupLabels
(
source
.
ToString
().
IndexOf
(
"HERE"
,
StringComparison
.
Ordinal
));
AssertEx
.
SetEqual
(
new
[]
{
"default"
,
"case int i:"
,
"label1"
},
symbols
.
Select
(
s
=>
s
.
ToTestDisplayString
()));
}
[
WorkItem
(
586815
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/586815"
)]
[
WorkItem
(
598371
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/598371"
)]
[
Fact
]
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs
浏览文件 @
674f4e1c
...
...
@@ -5608,9 +5608,9 @@ static void M1(object o)
"
;
var
compilation
=
CreateCompilationWithMscorlib45
(
source
);
compilation
.
VerifyDiagnostics
(
// (9,13): error CS0152: The switch statement contains multiple cases with the label value 'default
:
'
// (9,13): error CS0152: The switch statement contains multiple cases with the label value 'default'
// default:
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default
:
"
).
WithLocation
(
9
,
13
)
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
9
,
13
)
);
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/SwitchTests.cs
浏览文件 @
674f4e1c
...
...
@@ -377,19 +377,48 @@ public static void Main()
}
}"
;
CreateStandardCompilation
(
text
,
parseOptions
:
TestOptions
.
Regular6
).
VerifyDiagnostics
(
// (15,13): error CS0152: The switch statement contains multiple cases with the label value 'default
:
'
// (15,13): error CS0152: The switch statement contains multiple cases with the label value 'default'
// default: //CS0152
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default
:
"
).
WithLocation
(
15
,
13
)
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
15
,
13
)
);
CreateStandardCompilation
(
text
,
parseOptions
:
TestOptions
.
Regular6WithV7SwitchBinder
).
VerifyDiagnostics
(
// (15,13): error CS0152: The switch statement contains multiple cases with the label value 'default
:
'
// (15,13): error CS0152: The switch statement contains multiple cases with the label value 'default'
// default: //CS0152
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default
:
"
).
WithLocation
(
15
,
13
)
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
15
,
13
)
);
CreateStandardCompilation
(
text
).
VerifyDiagnostics
(
// (15,13): error CS0152: The switch statement contains multiple cases with the label value 'default
:
'
// (15,13): error CS0152: The switch statement contains multiple cases with the label value 'default'
// default: //CS0152
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default:"
).
WithLocation
(
15
,
13
)
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
15
,
13
)
);
}
[
Fact
]
public
void
CS0152_DuplicateDefaultLabel2
()
{
var
text
=
@"
public class TestClass
{
public static void Main()
{
int i = 10;
switch (i)
{
default:
break;
case (default):
break;
case 1:
break;
default: //CS0152
break;
}
}
}"
;
CreateStandardCompilation
(
text
,
parseOptions
:
TestOptions
.
Regular7_1
).
VerifyDiagnostics
(
// (15,13): error CS0152: The switch statement contains multiple cases with the label value 'default'
// default: //CS0152
Diagnostic
(
ErrorCode
.
ERR_DuplicateCaseLabel
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
15
,
13
)
);
}
...
...
@@ -2483,17 +2512,17 @@ public static int Main()
CreateStandardCompilation
(
text
,
parseOptions
:
TestOptions
.
Regular6
).
VerifyDiagnostics
(
// (14,13): error CS8070: Control cannot fall out of switch from final case label ('default')
// default: // CS8070
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default
:
"
).
WithLocation
(
14
,
13
)
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
14
,
13
)
);
CreateStandardCompilation
(
text
,
parseOptions
:
TestOptions
.
Regular6WithV7SwitchBinder
).
VerifyDiagnostics
(
// (14,13): error CS8070: Control cannot fall out of switch from final case label ('default')
// (14,13): error CS8070: Control cannot fall out of switch from final case label ('default
:
')
// default: // CS8070
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default:"
).
WithLocation
(
14
,
13
)
);
CreateStandardCompilation
(
text
).
VerifyDiagnostics
(
// (14,13): error CS8070: Control cannot fall out of switch from final case label ('default')
// default: // CS8070
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default
:
"
).
WithLocation
(
14
,
13
)
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
14
,
13
)
);
}
...
...
@@ -2589,9 +2618,10 @@ static int Main()
// (24,17): error CS8070: Control cannot fall out of switch from final case label ('case 5:')
// case 5:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"case 5:"
).
WithArguments
(
"case 5:"
).
WithLocation
(
24
,
17
),
// (32,17): error CS8070: Control cannot fall out of switch from final case label ('default
:
')
// (32,17): error CS8070: Control cannot fall out of switch from final case label ('default')
// default:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default:"
).
WithLocation
(
32
,
17
));
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
32
,
17
)
);
CreateStandardCompilation
(
text
,
parseOptions
:
TestOptions
.
Regular6WithV7SwitchBinder
).
VerifyDiagnostics
(
// (15,17): error CS8070: Control cannot fall out of switch from final case label ('case 11:')
// case 11:
...
...
@@ -2601,7 +2631,8 @@ static int Main()
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"case 5:"
).
WithArguments
(
"case 5:"
).
WithLocation
(
24
,
17
),
// (32,17): error CS8070: Control cannot fall out of switch from final case label ('default:')
// default:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default:"
).
WithLocation
(
32
,
17
));
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default:"
).
WithLocation
(
32
,
17
)
// BUG
);
CreateStandardCompilation
(
text
).
VerifyDiagnostics
(
// (15,17): error CS8070: Control cannot fall out of switch from final case label ('case 11:')
// case 11:
...
...
@@ -2609,9 +2640,10 @@ static int Main()
// (24,17): error CS8070: Control cannot fall out of switch from final case label ('case 5:')
// case 5:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"case 5:"
).
WithArguments
(
"case 5:"
).
WithLocation
(
24
,
17
),
// (32,17): error CS8070: Control cannot fall out of switch from final case label ('default
:
')
// (32,17): error CS8070: Control cannot fall out of switch from final case label ('default')
// default:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default:"
).
WithLocation
(
32
,
17
));
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
32
,
17
)
);
}
[
Fact
]
...
...
@@ -2627,9 +2659,9 @@ public void SwitchFallOut_Script()
Console.WriteLine(2);
}"
;
CreateCompilationWithMscorlib45
(
source
,
references
:
new
[]
{
SystemCoreRef
},
parseOptions
:
TestOptions
.
Script
).
VerifyDiagnostics
(
// (4,5): error CS0163: Control cannot fall through from one case label ('default
:
') to another
// (4,5): error CS0163: Control cannot fall through from one case label ('default') to another
// default:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallThrough
,
"default:"
).
WithArguments
(
"default
:
"
).
WithLocation
(
4
,
5
),
Diagnostic
(
ErrorCode
.
ERR_SwitchFallThrough
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
4
,
5
),
// (6,5): error CS8070: Control cannot fall out of switch from final case label ('case 2:')
// case 2:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"case 2:"
).
WithArguments
(
"case 2:"
).
WithLocation
(
6
,
5
)
...
...
@@ -2656,9 +2688,9 @@ public void SwitchFallOut_Submission()
// (4,5): error CS0163: Control cannot fall through from one case label ('case 1:') to another
// case 1:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallThrough
,
"case 1:"
).
WithArguments
(
"case 1:"
).
WithLocation
(
4
,
5
),
// (6,5): error CS8070: Control cannot fall out of switch from final case label ('default
:
')
// (6,5): error CS8070: Control cannot fall out of switch from final case label ('default')
// default:
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default
:
"
).
WithLocation
(
6
,
5
)
Diagnostic
(
ErrorCode
.
ERR_SwitchFallOut
,
"default:"
).
WithArguments
(
"default"
).
WithLocation
(
6
,
5
)
);
}
...
...
src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs
浏览文件 @
674f4e1c
...
...
@@ -705,7 +705,7 @@ void M()
var
labelSymbol
=
(
SourceLabelSymbol
)
symbol1
;
Assert
.
Null
(
labelSymbol
.
SwitchCaseLabelConstant
);
Assert
.
Equal
(
switchLabel
,
labelSymbol
.
IdentifierNodeOrToken
.
AsNode
());
Assert
.
Equal
(
"default
:
"
,
labelSymbol
.
Name
);
Assert
.
Equal
(
"default"
,
labelSymbol
.
Name
);
}
[
Fact
]
...
...
src/Compilers/CSharp/Test/Symbol/Symbols/Source/DeclaringSyntaxNodeTests.cs
浏览文件 @
674f4e1c
...
...
@@ -638,7 +638,7 @@ void m(int i)
CheckDeclaringSyntax
<
LabeledStatementSyntax
>(
comp
,
tree
,
"lab3"
,
SymbolKind
.
Label
);
CheckDeclaringSyntax
<
SwitchLabelSyntax
>(
comp
,
tree
,
"case 4:"
,
SymbolKind
.
Label
);
CheckDeclaringSyntax
<
SwitchLabelSyntax
>(
comp
,
tree
,
"case 3:"
,
SymbolKind
.
Label
);
CheckDeclaringSyntax
<
SwitchLabelSyntax
>(
comp
,
tree
,
"default
:
"
,
SymbolKind
.
Label
);
CheckDeclaringSyntax
<
SwitchLabelSyntax
>(
comp
,
tree
,
"default"
,
SymbolKind
.
Label
);
}
...
...
src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs
浏览文件 @
674f4e1c
...
...
@@ -2261,7 +2261,7 @@ static void Main()
default:
goto $$"
;
await
VerifyItemExistsAsync
(
markup
,
"default
:
"
);
await
VerifyItemExistsAsync
(
markup
,
"default"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)]
...
...
src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb
浏览文件 @
674f4e1c
...
...
@@ -574,6 +574,118 @@ class C
End
Using
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)
>
<
WorkItem
(
4677
,
"https://github.com/dotnet/roslyn/issues/4677"
)
>
Public
Async
Function
TestDefaultSwitchLabel
()
As
Task
Using
state
=
TestState
.
CreateCSharpTestState
(
<
Document
><
!
[
CDATA
[
class
C
{
public
void
M
(
object
o
)
{
switch
(
o
)
{
default
:
goto
$$
}
}
}
]]
></
Document
>
)
state
.
SendTypeChars
(
"d"
)
Await
state
.
AssertSelectedCompletionItem
(
displayText
:
=
"default"
,
isHardSelected
:
=
True
)
state
.
SendTypeChars
(
";"
)
Assert
.
Contains
(
"goto default;"
,
state
.
GetLineTextFromCaretPosition
(),
StringComparison
.
Ordinal
)
End
Using
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)
>
<
WorkItem
(
4677
,
"https://github.com/dotnet/roslyn/issues/4677"
)
>
Public
Async
Function
TestGotoOrdinaryLabel
()
As
Task
Using
state
=
TestState
.
CreateCSharpTestState
(
<
Document
><
!
[
CDATA
[
class
C
{
public
void
M
(
object
o
)
{
label1
:
goto
$$
}
}
]]
></
Document
>
)
state
.
SendTypeChars
(
"l"
)
Await
state
.
AssertSelectedCompletionItem
(
displayText
:
=
"label1"
,
isHardSelected
:
=
True
)
state
.
SendTypeChars
(
";"
)
Assert
.
Contains
(
"goto label1;"
,
state
.
GetLineTextFromCaretPosition
(),
StringComparison
.
Ordinal
)
End
Using
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)
>
<
WorkItem
(
4677
,
"https://github.com/dotnet/roslyn/issues/4677"
)
>
Public
Async
Function
TestEscapedDefaultLabel
()
As
Task
Using
state
=
TestState
.
CreateCSharpTestState
(
<
Document
><
!
[
CDATA
[
class
C
{
public
void
M
(
object
o
)
{
@
default
:
goto
$$
}
}
]]
></
Document
>
)
state
.
SendTypeChars
(
"d"
)
Await
state
.
AssertSelectedCompletionItem
(
displayText
:
=
"@default"
,
isHardSelected
:
=
True
)
state
.
SendTypeChars
(
";"
)
Assert
.
Contains
(
"goto @default;"
,
state
.
GetLineTextFromCaretPosition
(),
StringComparison
.
Ordinal
)
End
Using
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)
>
<
WorkItem
(
4677
,
"https://github.com/dotnet/roslyn/issues/4677"
)
>
Public
Async
Function
TestEscapedDefaultLabel2
()
As
Task
Using
state
=
TestState
.
CreateCSharpTestState
(
<
Document
><
!
[
CDATA
[
class
C
{
public
void
M
(
object
o
)
{
switch
(
o
)
{
default
:
@
default
:
goto
$$
}
}
}
]]
></
Document
>
)
state
.
SendTypeChars
(
"d"
)
Await
state
.
AssertSelectedCompletionItem
(
displayText
:
=
"default"
,
isHardSelected
:
=
True
)
state
.
SendTypeChars
(
";"
)
Assert
.
Contains
(
"goto default;"
,
state
.
GetLineTextFromCaretPosition
(),
StringComparison
.
Ordinal
)
End
Using
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)
>
<
WorkItem
(
4677
,
"https://github.com/dotnet/roslyn/issues/4677"
)
>
Public
Async
Function
TestEscapedDefaultLabelWithoutSwitch
()
As
Task
Using
state
=
TestState
.
CreateCSharpTestState
(
<
Document
><
!
[
CDATA
[
class
C
{
public
void
M
(
object
o
)
{
@
default
:
goto
$$
}
}
]]
></
Document
>
)
state
.
SendTypeChars
(
"d"
)
Await
state
.
AssertSelectedCompletionItem
(
displayText
:
=
"@default"
,
isHardSelected
:
=
True
)
state
.
SendTypeChars
(
";"
)
Assert
.
Contains
(
"goto @default;"
,
state
.
GetLineTextFromCaretPosition
(),
StringComparison
.
Ordinal
)
End
Using
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)
>
<
WorkItem
(
13527
,
"https://github.com/dotnet/roslyn/issues/13527"
)
>
Public
Async
Function
TestSymbolInTupleLiteral
()
As
Task
...
...
src/Features/CSharp/Portable/Completion/CompletionProviders/CompletionUtilities.cs
浏览文件 @
674f4e1c
...
...
@@ -107,6 +107,12 @@ public static string GetInsertionText(ISymbol symbol, SyntaxContext context)
}
}
if
(
symbol
.
Kind
==
SymbolKind
.
Label
&&
symbol
.
DeclaringSyntaxReferences
[
0
].
GetSyntax
().
Kind
()
==
SyntaxKind
.
DefaultSwitchLabel
)
{
return
symbol
.
Name
;
}
return
symbol
.
Name
.
EscapeIdentifier
(
isQueryContext
:
context
.
IsInQuery
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录