Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
326d72a9
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,发现更多精彩内容 >>
提交
326d72a9
编写于
4月 18, 2017
作者:
C
CyrusNajmabadi
提交者:
GitHub
4月 18, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16350 from CyrusNajmabadi/parserDiagnostics31
Move indexer parameter count checking out of the parser.
上级
86751585
f60be5af
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
120 addition
and
25 deletion
+120
-25
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
+1
-6
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
...rs/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
+7
-1
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
...ers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
+4
-1
src/Compilers/CSharp/Test/Syntax/Parsing/ParsingErrorRecoveryTests.cs
...s/CSharp/Test/Syntax/Parsing/ParsingErrorRecoveryTests.cs
+86
-16
src/Compilers/CSharp/Test/Syntax/Parsing/ScriptParsingTests.cs
...ompilers/CSharp/Test/Syntax/Parsing/ScriptParsingTests.cs
+22
-1
未找到文件。
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
浏览文件 @
326d72a9
...
...
@@ -3118,7 +3118,7 @@ private ConversionOperatorDeclarationSyntax ParseConversionOperatorDeclaration(S
semicolon
);
}
private
Memb
erDeclarationSyntax
ParseIndexerDeclaration
(
private
Index
erDeclarationSyntax
ParseIndexerDeclaration
(
SyntaxListBuilder
<
AttributeListSyntax
>
attributes
,
SyntaxListBuilder
modifiers
,
TypeSyntax
type
,
...
...
@@ -3136,11 +3136,6 @@ private ConversionOperatorDeclarationSyntax ParseConversionOperatorDeclaration(S
}
var
parameterList
=
this
.
ParseBracketedParameterList
();
// TODO: ReportExtensionMethods(parameters, retval);
if
(
parameterList
.
Parameters
.
Count
==
0
)
{
parameterList
=
this
.
AddErrorToLastToken
(
parameterList
,
ErrorCode
.
ERR_IndexerNeedsParam
);
}
AccessorListSyntax
accessorList
=
null
;
ArrowExpressionClauseSyntax
expressionBody
=
null
;
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs
浏览文件 @
326d72a9
...
...
@@ -766,13 +766,19 @@ private DeclarationModifiers MakeModifiers(SyntaxTokenList modifiers, bool isExp
return
mods
;
}
private
static
ImmutableArray
<
ParameterSymbol
>
MakeParameters
(
Binder
binder
,
SourcePropertySymbol
owner
,
BaseParameterListSyntax
parameterSyntaxOpt
,
DiagnosticBag
diagnostics
)
private
static
ImmutableArray
<
ParameterSymbol
>
MakeParameters
(
Binder
binder
,
SourcePropertySymbol
owner
,
BaseParameterListSyntax
parameterSyntaxOpt
,
DiagnosticBag
diagnostics
)
{
if
(
parameterSyntaxOpt
==
null
)
{
return
ImmutableArray
<
ParameterSymbol
>.
Empty
;
}
if
(
parameterSyntaxOpt
.
Parameters
.
Count
<
1
)
{
diagnostics
.
Add
(
ErrorCode
.
ERR_IndexerNeedsParam
,
parameterSyntaxOpt
.
GetLastToken
().
GetLocation
());
}
SyntaxToken
arglistToken
;
var
parameters
=
ParameterHelpers
.
MakeParameters
(
binder
,
owner
,
parameterSyntaxOpt
,
out
arglistToken
,
...
...
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
浏览文件 @
326d72a9
...
...
@@ -3802,7 +3802,10 @@ public class MyClass {
}
"
;
ParseAndValidate
(
test
,
Diagnostic
(
ErrorCode
.
ERR_IndexerNeedsParam
,
"]"
));
CreateCompilationWithMscorlib
(
test
).
VerifyDiagnostics
(
// (4,14): error CS1551: Indexers must have at least one parameter
// int this[] {
Diagnostic
(
ErrorCode
.
ERR_IndexerNeedsParam
,
"]"
).
WithLocation
(
4
,
14
));
}
[
Fact
]
...
...
src/Compilers/CSharp/Test/Syntax/Parsing/ParsingErrorRecoveryTests.cs
浏览文件 @
326d72a9
...
...
@@ -1870,11 +1870,27 @@ public void TestEndBraceAfterIndexerParameterStart()
var
agg
=
(
TypeDeclarationSyntax
)
file
.
Members
[
0
];
Assert
.
Equal
(
1
,
agg
.
Members
.
Count
);
Assert
.
Equal
(
SyntaxKind
.
IndexerDeclaration
,
agg
.
Members
[
0
].
Kind
());
Assert
.
Equal
(
4
,
file
.
Errors
().
Length
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_IndexerNeedsParam
,
file
.
Errors
()[
0
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_SyntaxError
,
file
.
Errors
()[
1
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_LbraceExpected
,
file
.
Errors
()[
2
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_RbraceExpected
,
file
.
Errors
()[
3
].
Code
);
Assert
.
Equal
(
3
,
file
.
Errors
().
Length
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_SyntaxError
,
file
.
Errors
()[
0
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_LbraceExpected
,
file
.
Errors
()[
1
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_RbraceExpected
,
file
.
Errors
()[
2
].
Code
);
CreateCompilationWithMscorlib
(
text
).
VerifyDiagnostics
(
// (1,21): error CS1003: Syntax error, ']' expected
// class c { int this[ }
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
"}"
).
WithArguments
(
"]"
,
"}"
).
WithLocation
(
1
,
21
),
// (1,21): error CS1514: { expected
// class c { int this[ }
Diagnostic
(
ErrorCode
.
ERR_LbraceExpected
,
"}"
).
WithLocation
(
1
,
21
),
// (1,22): error CS1513: } expected
// class c { int this[ }
Diagnostic
(
ErrorCode
.
ERR_RbraceExpected
,
""
).
WithLocation
(
1
,
22
),
// (1,15): error CS0548: 'c.this': property or indexer must have at least one accessor
// class c { int this[ }
Diagnostic
(
ErrorCode
.
ERR_PropertyWithNoAccessors
,
"this"
).
WithArguments
(
"c.this"
).
WithLocation
(
1
,
15
),
// (1,19): error CS1551: Indexers must have at least one parameter
// class c { int this[ }
Diagnostic
(
ErrorCode
.
ERR_IndexerNeedsParam
,
"["
).
WithLocation
(
1
,
19
));
}
[
Fact
]
...
...
@@ -1968,9 +1984,19 @@ public void TestGarbageAfterIndexerParameterStart()
var
agg
=
(
TypeDeclarationSyntax
)
file
.
Members
[
0
];
Assert
.
Equal
(
1
,
agg
.
Members
.
Count
);
Assert
.
Equal
(
SyntaxKind
.
IndexerDeclaration
,
agg
.
Members
[
0
].
Kind
());
Assert
.
Equal
(
2
,
file
.
Errors
().
Length
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_IndexerNeedsParam
,
file
.
Errors
()[
0
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_UnexpectedCharacter
,
file
.
Errors
()[
1
].
Code
);
Assert
.
Equal
(
1
,
file
.
Errors
().
Length
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_UnexpectedCharacter
,
file
.
Errors
()[
0
].
Code
);
CreateCompilationWithMscorlib
(
text
).
VerifyDiagnostics
(
// (1,21): error CS1056: Unexpected character '$'
// class c { int this[ $ ] { } }
Diagnostic
(
ErrorCode
.
ERR_UnexpectedCharacter
,
""
).
WithArguments
(
"$"
).
WithLocation
(
1
,
21
),
// (1,15): error CS0548: 'c.this': property or indexer must have at least one accessor
// class c { int this[ $ ] { } }
Diagnostic
(
ErrorCode
.
ERR_PropertyWithNoAccessors
,
"this"
).
WithArguments
(
"c.this"
).
WithLocation
(
1
,
15
),
// (1,23): error CS1551: Indexers must have at least one parameter
// class c { int this[ $ ] { } }
Diagnostic
(
ErrorCode
.
ERR_IndexerNeedsParam
,
"]"
).
WithLocation
(
1
,
23
));
}
[
Fact
]
...
...
@@ -2041,11 +2067,27 @@ public void TestMethodAfterIndexerParameterStart()
Assert
.
Equal
(
2
,
agg
.
Members
.
Count
);
Assert
.
Equal
(
SyntaxKind
.
IndexerDeclaration
,
agg
.
Members
[
0
].
Kind
());
Assert
.
Equal
(
SyntaxKind
.
MethodDeclaration
,
agg
.
Members
[
1
].
Kind
());
Assert
.
Equal
(
4
,
file
.
Errors
().
Length
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_IndexerNeedsParam
,
file
.
Errors
()[
0
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_SyntaxError
,
file
.
Errors
()[
1
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_LbraceExpected
,
file
.
Errors
()[
2
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_RbraceExpected
,
file
.
Errors
()[
3
].
Code
);
Assert
.
Equal
(
3
,
file
.
Errors
().
Length
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_SyntaxError
,
file
.
Errors
()[
0
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_LbraceExpected
,
file
.
Errors
()[
1
].
Code
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_RbraceExpected
,
file
.
Errors
()[
2
].
Code
);
CreateCompilationWithMscorlib
(
text
).
VerifyDiagnostics
(
// (1,21): error CS1003: Syntax error, ']' expected
// class c { int this[ public void m() { } }
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
"public"
).
WithArguments
(
"]"
,
"public"
).
WithLocation
(
1
,
21
),
// (1,21): error CS1514: { expected
// class c { int this[ public void m() { } }
Diagnostic
(
ErrorCode
.
ERR_LbraceExpected
,
"public"
).
WithLocation
(
1
,
21
),
// (1,21): error CS1513: } expected
// class c { int this[ public void m() { } }
Diagnostic
(
ErrorCode
.
ERR_RbraceExpected
,
"public"
).
WithLocation
(
1
,
21
),
// (1,15): error CS0548: 'c.this': property or indexer must have at least one accessor
// class c { int this[ public void m() { } }
Diagnostic
(
ErrorCode
.
ERR_PropertyWithNoAccessors
,
"this"
).
WithArguments
(
"c.this"
).
WithLocation
(
1
,
15
),
// (1,19): error CS1551: Indexers must have at least one parameter
// class c { int this[ public void m() { } }
Diagnostic
(
ErrorCode
.
ERR_IndexerNeedsParam
,
"["
).
WithLocation
(
1
,
19
));
}
[
Fact
]
...
...
@@ -6679,9 +6721,6 @@ public void ColonColonInExplicitInterfaceMember()
// (2,4): error CS1003: Syntax error, '.' expected
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
"::"
).
WithArguments
(
"."
,
"::"
),
// (3,1): error CS1551: Indexers must have at least one parameter
//
Diagnostic
(
ErrorCode
.
ERR_IndexerNeedsParam
,
""
),
// (2,10): error CS1003: Syntax error, '[' expected
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
""
).
WithArguments
(
"["
,
""
),
...
...
@@ -6694,6 +6733,37 @@ public void ColonColonInExplicitInterfaceMember()
// (2,10): error CS1513: } expected
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_RbraceExpected
,
""
));
CreateCompilationWithMscorlib
(
text
).
VerifyDiagnostics
(
// (2,4): error CS1003: Syntax error, '.' expected
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
"::"
).
WithArguments
(
"."
,
"::"
).
WithLocation
(
2
,
4
),
// (2,10): error CS1003: Syntax error, '[' expected
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
""
).
WithArguments
(
"["
,
""
).
WithLocation
(
2
,
10
),
// (2,10): error CS1003: Syntax error, ']' expected
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
""
).
WithArguments
(
"]"
,
""
).
WithLocation
(
2
,
10
),
// (2,10): error CS1514: { expected
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_LbraceExpected
,
""
).
WithLocation
(
2
,
10
),
// (2,10): error CS1513: } expected
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_RbraceExpected
,
""
).
WithLocation
(
2
,
10
),
// (2,3): error CS0246: The type or namespace name '_' could not be found (are you missing a using directive or an assembly reference?)
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"_"
).
WithArguments
(
"_"
).
WithLocation
(
2
,
3
),
// (2,1): error CS0246: The type or namespace name '_' could not be found (are you missing a using directive or an assembly reference?)
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"_"
).
WithArguments
(
"_"
).
WithLocation
(
2
,
1
),
// error CS1551: Indexers must have at least one parameter
Diagnostic
(
ErrorCode
.
ERR_IndexerNeedsParam
).
WithLocation
(
1
,
1
),
// (2,3): error CS0538: '_' in explicit interface declaration is not an interface
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_ExplicitInterfaceImplementationNotInterface
,
"_"
).
WithArguments
(
"_"
).
WithLocation
(
2
,
3
),
// (2,6): error CS0548: '<invalid-global-code>.this': property or indexer must have at least one accessor
// _ _::this
Diagnostic
(
ErrorCode
.
ERR_PropertyWithNoAccessors
,
"this"
).
WithArguments
(
"<invalid-global-code>.this"
).
WithLocation
(
2
,
6
));
}
[
WorkItem
(
649806
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/649806"
)]
...
...
src/Compilers/CSharp/Test/Syntax/Parsing/ScriptParsingTests.cs
浏览文件 @
326d72a9
...
...
@@ -1571,9 +1571,30 @@ public void Error_IndexerDefinition()
new
ErrorDescription
{
Code
=
1001
,
Line
=
1
,
Column
=
13
},
new
ErrorDescription
{
Code
=
1003
,
Line
=
1
,
Column
=
13
},
new
ErrorDescription
{
Code
=
1003
,
Line
=
1
,
Column
=
17
},
new
ErrorDescription
{
Code
=
1551
,
Line
=
1
,
Column
=
17
},
new
ErrorDescription
{
Code
=
1514
,
Line
=
1
,
Column
=
17
},
new
ErrorDescription
{
Code
=
1513
,
Line
=
1
,
Column
=
17
});
CreateCompilationWithMscorlib
(
test
).
VerifyDiagnostics
(
// (1,13): error CS1003: Syntax error, '[' expected
// string this ="";
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
"="
).
WithArguments
(
"["
,
"="
).
WithLocation
(
1
,
13
),
// (1,13): error CS1001: Identifier expected
// string this ="";
Diagnostic
(
ErrorCode
.
ERR_IdentifierExpected
,
"="
).
WithLocation
(
1
,
13
),
// (1,17): error CS1003: Syntax error, ']' expected
// string this ="";
Diagnostic
(
ErrorCode
.
ERR_SyntaxError
,
""
).
WithArguments
(
"]"
,
""
).
WithLocation
(
1
,
17
),
// (1,17): error CS1514: { expected
// string this ="";
Diagnostic
(
ErrorCode
.
ERR_LbraceExpected
,
""
).
WithLocation
(
1
,
17
),
// (1,17): error CS1513: } expected
// string this ="";
Diagnostic
(
ErrorCode
.
ERR_RbraceExpected
,
""
).
WithLocation
(
1
,
17
),
// (1,8): error CS0548: '<invalid-global-code>.this': property or indexer must have at least one accessor
// string this ="";
Diagnostic
(
ErrorCode
.
ERR_PropertyWithNoAccessors
,
"this"
).
WithArguments
(
"<invalid-global-code>.this"
).
WithLocation
(
1
,
8
),
// error CS1551: Indexers must have at least one parameter
Diagnostic
(
ErrorCode
.
ERR_IndexerNeedsParam
).
WithLocation
(
1
,
1
));
}
#
endregion
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录