Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5629d53d
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,发现更多精彩内容 >>
未验证
提交
5629d53d
编写于
12月 09, 2019
作者:
F
Fredric Silberberg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update with PR feedback.
上级
e9981eec
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
75 addition
and
72 deletion
+75
-72
src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
+75
-72
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
浏览文件 @
5629d53d
...
...
@@ -227,8 +227,9 @@ internal partial class Binder
{
case
SyntaxKind
.
PredefinedType
:
case
SyntaxKind
.
NullableType
:
break
;
case
SyntaxKind
.
PointerType
:
// Pointer error is reported by IsValidTypeConstraint
break
;
default
:
if
(!
SyntaxFacts
.
IsName
(
typeSyntax
.
Kind
()))
{
...
...
@@ -401,7 +402,7 @@ private TypeParameterConstraintClause GetDefaultTypeParameterConstraintClause(Ty
ArrayBuilder
<
TypeWithAnnotations
>
constraintTypes
,
DiagnosticBag
diagnostics
)
{
if
(!
I
sValidConstraintType
(
syntax
,
type
,
diagnostics
))
if
(!
i
sValidConstraintType
(
syntax
,
type
,
diagnostics
))
{
return
false
;
}
...
...
@@ -459,89 +460,91 @@ private TypeParameterConstraintClause GetDefaultTypeParameterConstraintClause(Ty
}
return
true
;
}
/// <summary>
/// Returns true if the type is a valid constraint type.
/// Otherwise returns false and generates a diagnostic.
/// </summary>
private
static
bool
IsValidConstraintType
(
TypeConstraintSyntax
syntax
,
TypeWithAnnotations
typeWithAnnotations
,
DiagnosticBag
diagnostics
)
{
TypeSymbol
type
=
typeWithAnnotations
.
Type
;
switch
(
type
.
SpecialType
)
// Returns true if the type is a valid constraint type.
// Otherwise returns false and generates a diagnostic.
static
bool
isValidConstraintType
(
TypeConstraintSyntax
syntax
,
TypeWithAnnotations
typeWithAnnotations
,
DiagnosticBag
diagnostics
)
{
case
SpecialType
.
System_Enum
:
CheckFeatureAvailability
(
syntax
,
MessageID
.
IDS_FeatureEnumGenericTypeConstraint
,
diagnostics
);
break
;
case
SpecialType
.
System_Delegate
:
case
SpecialType
.
System_MulticastDelegate
:
CheckFeatureAvailability
(
syntax
,
MessageID
.
IDS_FeatureDelegateGenericTypeConstraint
,
diagnostics
);
break
;
case
SpecialType
.
System_Object
:
case
SpecialType
.
System_ValueType
:
case
SpecialType
.
System_Array
:
// "Constraint cannot be special class '{0}'"
Error
(
diagnostics
,
ErrorCode
.
ERR_SpecialTypeAsBound
,
syntax
,
type
);
return
false
;
}
TypeSymbol
type
=
typeWithAnnotations
.
Type
;
switch
(
type
.
TypeKind
)
{
case
TypeKind
.
Error
:
case
TypeKind
.
TypeParameter
:
return
true
;
switch
(
type
.
SpecialType
)
{
case
SpecialType
.
System_Enum
:
CheckFeatureAvailability
(
syntax
,
MessageID
.
IDS_FeatureEnumGenericTypeConstraint
,
diagnostics
);
break
;
case
SpecialType
.
System_Delegate
:
case
SpecialType
.
System_MulticastDelegate
:
CheckFeatureAvailability
(
syntax
,
MessageID
.
IDS_FeatureDelegateGenericTypeConstraint
,
diagnostics
);
break
;
case
SpecialType
.
System_Object
:
case
SpecialType
.
System_ValueType
:
case
SpecialType
.
System_Array
:
// "Constraint cannot be special class '{0}'"
Error
(
diagnostics
,
ErrorCode
.
ERR_SpecialTypeAsBound
,
syntax
,
type
);
return
false
;
}
case
TypeKind
.
Interface
:
break
;
switch
(
type
.
TypeKind
)
{
case
TypeKind
.
Error
:
case
TypeKind
.
TypeParameter
:
return
true
;
case
TypeKind
.
Dynamic
:
// "Constraint cannot be the dynamic type"
Error
(
diagnostics
,
ErrorCode
.
ERR_DynamicTypeAsBound
,
syntax
);
return
false
;
case
TypeKind
.
Interface
:
break
;
case
TypeKind
.
Class
:
if
(
type
.
IsSealed
)
{
goto
case
TypeKind
.
Struct
;
}
else
if
(
type
.
IsStatic
)
{
// "'{0}': static classes cannot be used as constraints"
Error
(
diagnostics
,
ErrorCode
.
ERR_ConstraintIsStaticClass
,
syntax
,
type
);
case
TypeKind
.
Dynamic
:
// "Constraint cannot be the dynamic type"
Error
(
diagnostics
,
ErrorCode
.
ERR_DynamicTypeAsBound
,
syntax
);
return
false
;
}
break
;
case
TypeKind
.
Delegate
:
case
TypeKind
.
Enum
:
case
TypeKind
.
Struct
:
// "'{0}' is not a valid constraint. A type used as a constraint must be an interface, a non-sealed class or a type parameter."
Error
(
diagnostics
,
ErrorCode
.
ERR_BadBoundType
,
syntax
,
type
);
return
false
;
case
TypeKind
.
Class
:
if
(
type
.
IsSealed
)
{
goto
case
TypeKind
.
Struct
;
}
else
if
(
type
.
IsStatic
)
{
// "'{0}': static classes cannot be used as constraints"
Error
(
diagnostics
,
ErrorCode
.
ERR_ConstraintIsStaticClass
,
syntax
,
type
);
return
false
;
}
break
;
case
TypeKind
.
Array
:
case
TypeKind
.
Pointer
:
// CS0706 already reported by binding above.
return
false
;
case
TypeKind
.
Delegate
:
case
TypeKind
.
Enum
:
case
TypeKind
.
Struct
:
// "'{0}' is not a valid constraint. A type used as a constraint must be an interface, a non-sealed class or a type parameter."
Error
(
diagnostics
,
ErrorCode
.
ERR_BadBoundType
,
syntax
,
type
);
return
false
;
case
TypeKind
.
Submission
:
// script class is synthesized, never used as a constraint
case
TypeKind
.
Array
:
// CS0706 already reported by binding above.
return
false
;
default
:
throw
ExceptionUtilities
.
UnexpectedValue
(
type
.
TypeKind
);
}
case
TypeKind
.
Pointer
:
// "Invalid constraint type. A type used as a constraint must be an interface, a non-sealed class or a type parameter."
Error
(
diagnostics
,
ErrorCode
.
ERR_BadConstraintType
,
syntax
.
GetLocation
());
return
false
;
if
(
type
.
ContainsDynamic
())
{
// "Constraint cannot be a dynamic type '{0}'"
Error
(
diagnostics
,
ErrorCode
.
ERR_ConstructedDynamicTypeAsBound
,
syntax
,
type
);
return
false
;
}
case
TypeKind
.
Submission
:
// script class is synthesized, never used as a constraint
return
true
;
default
:
throw
ExceptionUtilities
.
UnexpectedValue
(
type
.
TypeKind
);
}
if
(
type
.
ContainsDynamic
())
{
// "Constraint cannot be a dynamic type '{0}'"
Error
(
diagnostics
,
ErrorCode
.
ERR_ConstructedDynamicTypeAsBound
,
syntax
,
type
);
return
false
;
}
return
true
;
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录