Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
00d2096a
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,发现更多精彩内容 >>
提交
00d2096a
编写于
12月 28, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move diagnostic from parser to later phase.
上级
d0a377e6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
35 deletion
+48
-35
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
+14
-22
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
...Sharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
+5
-0
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
...s/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
+9
-1
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
...ers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
+20
-12
未找到文件。
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
浏览文件 @
00d2096a
...
...
@@ -1584,7 +1584,7 @@ private TypeDeclarationSyntax ParseClassOrStructOrInterfaceDeclaration(SyntaxLis
var
saveTerm
=
_termState
;
_termState
|=
TerminatorState
.
IsPossibleAggregateClauseStartOrStop
;
var
name
=
this
.
ParseIdentifierToken
();
var
typeParameters
=
this
.
ParseTypeParameterList
(
allowVariance
:
classOrStructOrInterface
.
Kind
==
SyntaxKind
.
InterfaceKeyword
);
var
typeParameters
=
this
.
ParseTypeParameterList
();
_termState
=
saveTerm
;
bool
hasTypeParams
=
typeParameters
!=
null
;
...
...
@@ -4985,7 +4985,7 @@ private bool IsLocalFunctionAfterIdentifier()
try
{
var
typeParameterListOpt
=
this
.
ParseTypeParameterList
(
allowVariance
:
false
);
var
typeParameterListOpt
=
this
.
ParseTypeParameterList
();
var
paramList
=
ParseParenthesizedParameterList
(
allowThisKeyword
:
true
,
allowDefaults
:
true
,
allowAttributes
:
true
);
...
...
@@ -5078,7 +5078,7 @@ private DelegateDeclarationSyntax ParseDelegateDeclaration(SyntaxListBuilder<Att
var
saveTerm
=
_termState
;
_termState
|=
TerminatorState
.
IsEndOfMethodSignature
;
var
name
=
this
.
ParseIdentifierToken
();
var
typeParameters
=
this
.
ParseTypeParameterList
(
allowVariance
:
true
);
var
typeParameters
=
this
.
ParseTypeParameterList
();
var
parameterList
=
this
.
ParseParenthesizedParameterList
(
allowThisKeyword
:
false
,
allowDefaults
:
true
,
allowAttributes
:
true
);
var
constraints
=
default
(
SyntaxListBuilder
<
TypeParameterConstraintClauseSyntax
>);
try
...
...
@@ -5111,7 +5111,7 @@ private EnumDeclarationSyntax ParseEnumDeclaration(SyntaxListBuilder<AttributeLi
var
name
=
this
.
ParseIdentifierToken
();
// check to see if the user tried to create a generic enum.
var
typeParameters
=
this
.
ParseTypeParameterList
(
allowVariance
:
true
);
var
typeParameters
=
this
.
ParseTypeParameterList
();
if
(
typeParameters
!=
null
)
{
...
...
@@ -5404,7 +5404,7 @@ private bool IsCurrentTokenPartialKeywordOfPartialMethodOrType()
return
false
;
}
private
TypeParameterListSyntax
ParseTypeParameterList
(
bool
allowVariance
)
private
TypeParameterListSyntax
ParseTypeParameterList
()
{
if
(
this
.
CurrentToken
.
Kind
!=
SyntaxKind
.
LessThanToken
)
{
...
...
@@ -5420,7 +5420,7 @@ private TypeParameterListSyntax ParseTypeParameterList(bool allowVariance)
open
=
CheckFeatureAvailability
(
open
,
MessageID
.
IDS_FeatureGenerics
);
// first parameter
parameters
.
Add
(
this
.
ParseTypeParameter
(
allowVariance
));
parameters
.
Add
(
this
.
ParseTypeParameter
());
// remaining parameter & commas
while
(
true
)
...
...
@@ -5432,7 +5432,7 @@ private TypeParameterListSyntax ParseTypeParameterList(bool allowVariance)
else
if
(
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
CommaToken
)
{
parameters
.
AddSeparator
(
this
.
EatToken
(
SyntaxKind
.
CommaToken
));
parameters
.
Add
(
this
.
ParseTypeParameter
(
allowVariance
));
parameters
.
Add
(
this
.
ParseTypeParameter
());
}
else
if
(
this
.
SkipBadTypeParameterListTokens
(
parameters
,
SyntaxKind
.
CommaToken
)
==
PostSkipAction
.
Abort
)
{
...
...
@@ -5460,7 +5460,7 @@ private PostSkipAction SkipBadTypeParameterListTokens(SeparatedSyntaxListBuilder
expected
);
}
private
TypeParameterSyntax
ParseTypeParameter
(
bool
allowVariance
)
private
TypeParameterSyntax
ParseTypeParameter
()
{
if
(
this
.
IsPossibleTypeParameterConstraintClauseStart
())
{
...
...
@@ -5482,18 +5482,10 @@ private TypeParameterSyntax ParseTypeParameter(bool allowVariance)
}
SyntaxToken
varianceToken
=
null
;
if
(
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
InKeyword
||
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
OutKeyword
)
if
(
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
InKeyword
||
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
OutKeyword
)
{
// Again, we always recognize the variance syntax, but give an error if
// it is not appropriate.
varianceToken
=
this
.
EatToken
();
varianceToken
=
CheckFeatureAvailability
(
varianceToken
,
MessageID
.
IDS_FeatureTypeVariance
);
if
(!
allowVariance
)
{
varianceToken
=
this
.
AddError
(
varianceToken
,
ErrorCode
.
ERR_IllegalVarianceSyntax
);
}
varianceToken
=
CheckFeatureAvailability
(
this
.
EatToken
(),
MessageID
.
IDS_FeatureTypeVariance
);
}
return
_syntaxFactory
.
TypeParameter
(
attrs
,
varianceToken
,
this
.
ParseIdentifierToken
());
...
...
@@ -5877,7 +5869,7 @@ private bool IsOpenName()
beforeIdentifierPoint
=
GetResetPoint
();
beforeIdentifierPointSet
=
true
;
identifierOrThisOpt
=
this
.
EatToken
();
typeParameterListOpt
=
this
.
ParseTypeParameterList
(
allowVariance
:
false
);
typeParameterListOpt
=
this
.
ParseTypeParameterList
();
break
;
}
...
...
@@ -5911,7 +5903,7 @@ private bool IsOpenName()
}
identifierOrThisOpt
=
this
.
ParseIdentifierToken
();
typeParameterListOpt
=
this
.
ParseTypeParameterList
(
allowVariance
:
false
);
typeParameterListOpt
=
this
.
ParseTypeParameterList
();
break
;
}
else
...
...
@@ -8848,7 +8840,7 @@ private static bool IsAccessibilityModifier(SyntaxKind kind)
_pool
.
Free
(
badBuilder
);
}
TypeParameterListSyntax
typeParameterListOpt
=
this
.
ParseTypeParameterList
(
allowVariance
:
false
);
TypeParameterListSyntax
typeParameterListOpt
=
this
.
ParseTypeParameterList
();
// "await f<T>()" still makes sense, so don't force accept a local function if there's a type parameter list.
ParameterListSyntax
paramList
=
this
.
ParseParenthesizedParameterList
(
allowThisKeyword
:
true
,
allowDefaults
:
true
,
allowAttributes
:
true
);
// "await x()" is ambiguous (see note at start of this method), but we assume "await x(await y)" is meant to be a function if it's in a non-async context.
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
浏览文件 @
00d2096a
...
...
@@ -803,6 +803,11 @@ private ImmutableArray<TypeParameterSymbol> MakeTypeParameters(MethodDeclaration
for
(
int
ordinal
=
0
;
ordinal
<
typeParameters
.
Count
;
ordinal
++)
{
var
parameter
=
typeParameters
[
ordinal
];
if
(
parameter
.
VarianceKeyword
.
Kind
()
!=
SyntaxKind
.
None
)
{
diagnostics
.
Add
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
parameter
.
VarianceKeyword
.
GetLocation
());
}
var
identifier
=
parameter
.
Identifier
;
var
location
=
identifier
.
GetLocation
();
var
name
=
identifier
.
ValueText
;
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs
浏览文件 @
00d2096a
...
...
@@ -132,7 +132,8 @@ private ImmutableArray<TypeParameterSymbol> MakeTypeParameters(DiagnosticBag dia
var
syntaxTree
=
syntaxRef
.
SyntaxTree
;
TypeParameterListSyntax
tpl
;
switch
(
typeDecl
.
Kind
())
SyntaxKind
typeKind
=
typeDecl
.
Kind
();
switch
(
typeKind
)
{
case
SyntaxKind
.
ClassDeclaration
:
case
SyntaxKind
.
StructDeclaration
:
...
...
@@ -150,11 +151,18 @@ private ImmutableArray<TypeParameterSymbol> MakeTypeParameters(DiagnosticBag dia
throw
ExceptionUtilities
.
UnexpectedValue
(
typeDecl
.
Kind
());
}
bool
isInterfaceOrDelegate
=
typeKind
==
SyntaxKind
.
InterfaceDeclaration
||
typeKind
==
SyntaxKind
.
DelegateDeclaration
;
var
parameterBuilder
=
new
List
<
TypeParameterBuilder
>();
parameterBuilders1
.
Add
(
parameterBuilder
);
int
i
=
0
;
foreach
(
var
tp
in
tpl
.
Parameters
)
{
if
(
tp
.
VarianceKeyword
.
Kind
()
!=
SyntaxKind
.
None
&&
!
isInterfaceOrDelegate
)
{
diagnostics
.
Add
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
tp
.
VarianceKeyword
.
GetLocation
());
}
var
name
=
typeParameterNames
[
i
];
var
location
=
new
SourceLocation
(
tp
.
Identifier
);
var
varianceKind
=
typeParameterVarianceKeywords
[
i
];
...
...
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
浏览文件 @
00d2096a
...
...
@@ -4138,26 +4138,34 @@ struct S<out U> { }
delegate void D<in U>();
class B<out U> { }
}"
;
ParseAndValidate
(
test
,
// (3,12): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"in"
).
WithLocation
(
3
,
12
),
// (4,12): error CS7002: Unexpected use of a generic name
Diagnostic
(
ErrorCode
.
ERR_UnexpectedGenericName
,
"this"
).
WithLocation
(
4
,
12
),
// (4,17): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
4
,
17
),
CreateCompilationWithMscorlib
(
test
).
GetDeclarationDiagnostics
().
Verify
(
// (6,10): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
// struct S<out T>
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
6
,
10
),
// (8,12): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
// void M<out U>();
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
8
,
12
),
// (3,12): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
// void M<in U>();
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"in"
).
WithLocation
(
3
,
12
),
// (8,10): error CS0501: 'S<T>.M<U>()' must declare a body because it is not marked abstract, extern, or partial
// void M<out U>();
Diagnostic
(
ErrorCode
.
ERR_ConcreteMissingBody
,
"M"
).
WithArguments
(
"S<T>.M<U>()"
).
WithLocation
(
8
,
10
),
// (11,9): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
// class A<out T>
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
11
,
9
),
// (13, 12): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
// (13,12): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
// void M<out U>();
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
13
,
12
),
// (15, 14): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
15
,
14
),
// (13,10): error CS0501: 'A<T>.M<U>()' must declare a body because it is not marked abstract, extern, or partial
// void M<out U>();
Diagnostic
(
ErrorCode
.
ERR_ConcreteMissingBody
,
"M"
).
WithArguments
(
"A<T>.M<U>()"
).
WithLocation
(
13
,
10
),
// (17,13): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
17
,
13
));
// class B<out U> { }
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
17
,
13
),
// (15,14): error CS1960: Invalid variance modifier. Only interface and delegate type parameters can be specified as variant.
// struct S<out U> { }
Diagnostic
(
ErrorCode
.
ERR_IllegalVarianceSyntax
,
"out"
).
WithLocation
(
15
,
14
));
}
[
Fact
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录