Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4fc42f26
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,发现更多精彩内容 >>
提交
4fc42f26
编写于
11月 26, 2015
作者:
L
Llewellyn Pritchard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #7081 for ConstantTests.cs
上级
251956f1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
123 addition
and
42 deletion
+123
-42
src/Compilers/CSharp/Test/Semantic/Semantics/ConstantTests.cs
...Compilers/CSharp/Test/Semantic/Semantics/ConstantTests.cs
+123
-42
未找到文件。
src/Compilers/CSharp/Test/Semantic/Semantics/ConstantTests.cs
浏览文件 @
4fc42f26
...
...
@@ -680,7 +680,7 @@ void M()
[
Fact
]
public
void
TestEnumOverflowErrors
()
{
TestErrors
(
string
source
=
@"enum S8 : sbyte { Min = sbyte.MinValue, MinPlusOne, Max = sbyte.MaxValue }
enum U8 : byte { Min = byte.MinValue, MinPlusOne, Max = byte.MaxValue }
enum S16 : short { Min = short.MinValue, MinPlusOne, Max = short.MaxValue }
...
...
@@ -771,47 +771,128 @@ static void M()
F(S64.Min - 2); // overflows at compile time in checked mode
F(U64.Min - 2); // overflows at compile time in checked mode
}
}"
,
"'S8.Max + 1' error CS0221: Constant value '128' cannot be converted to a 'S8' (use 'unchecked' syntax to override)"
,
"'U8.Max + 1' error CS0221: Constant value '256' cannot be converted to a 'U8' (use 'unchecked' syntax to override)"
,
"'S16.Max + 1' error CS0221: Constant value '32768' cannot be converted to a 'S16' (use 'unchecked' syntax to override)"
,
"'U16.Max + 1' error CS0221: Constant value '65536' cannot be converted to a 'U16' (use 'unchecked' syntax to override)"
,
"'S32.Max + 1' error CS0220: The operation overflows at compile time in checked mode"
,
"'U32.Max + 1' error CS0220: The operation overflows at compile time in checked mode"
,
"'S64.Max + 1' error CS0220: The operation overflows at compile time in checked mode"
,
"'U64.Max + 1' error CS0220: The operation overflows at compile time in checked mode"
,
"'2 + S8.Max' error CS0221: Constant value '129' cannot be converted to a 'S8' (use 'unchecked' syntax to override)"
,
"'2 + U8.Max' error CS0221: Constant value '257' cannot be converted to a 'U8' (use 'unchecked' syntax to override)"
,
"'2 + S16.Max' error CS0221: Constant value '32769' cannot be converted to a 'S16' (use 'unchecked' syntax to override)"
,
"'2 + U16.Max' error CS0221: Constant value '65537' cannot be converted to a 'U16' (use 'unchecked' syntax to override)"
,
"'2 + S32.Max' error CS0220: The operation overflows at compile time in checked mode"
,
"'2 + U32.Max' error CS0220: The operation overflows at compile time in checked mode"
,
"'2 + S64.Max' error CS0220: The operation overflows at compile time in checked mode"
,
"'2 + U64.Max' error CS0220: The operation overflows at compile time in checked mode"
,
"'U8.Min - U8.MinPlusOne' error CS0221: Constant value '-1' cannot be converted to a 'byte' (use 'unchecked' syntax to override)"
,
"'U16.Min - U16.MinPlusOne' error CS0221: Constant value '-1' cannot be converted to a 'ushort' (use 'unchecked' syntax to override)"
,
"'U32.Min - U32.MinPlusOne' error CS0220: The operation overflows at compile time in checked mode"
,
"'U64.Min - U64.MinPlusOne' error CS0220: The operation overflows at compile time in checked mode"
,
"'S8.Min - S8.Max' error CS0221: Constant value '-255' cannot be converted to a 'sbyte' (use 'unchecked' syntax to override)"
,
"'U8.Min - U8.Max' error CS0221: Constant value '-255' cannot be converted to a 'byte' (use 'unchecked' syntax to override)"
,
"'S16.Min - S16.Max' error CS0221: Constant value '-65535' cannot be converted to a 'short' (use 'unchecked' syntax to override)"
,
"'U16.Min - U16.Max' error CS0221: Constant value '-65535' cannot be converted to a 'ushort' (use 'unchecked' syntax to override)"
,
"'S32.Min - S32.Max' error CS0220: The operation overflows at compile time in checked mode"
,
"'U32.Min - U32.Max' error CS0220: The operation overflows at compile time in checked mode"
,
"'S64.Min - S64.Max' error CS0220: The operation overflows at compile time in checked mode"
,
"'U64.Min - U64.Max' error CS0220: The operation overflows at compile time in checked mode"
,
"'S8.Max - S8.Min' error CS0221: Constant value '255' cannot be converted to a 'sbyte' (use 'unchecked' syntax to override)"
,
"'S16.Max - S16.Min' error CS0221: Constant value '65535' cannot be converted to a 'short' (use 'unchecked' syntax to override)"
,
"'S32.Max - S32.Min' error CS0220: The operation overflows at compile time in checked mode"
,
"'S64.Max - S64.Min' error CS0220: The operation overflows at compile time in checked mode"
,
"'S8.Min - 2' error CS0221: Constant value '-130' cannot be converted to a 'S8' (use 'unchecked' syntax to override)"
,
"'U8.Min - 2' error CS0221: Constant value '-2' cannot be converted to a 'U8' (use 'unchecked' syntax to override)"
,
"'S16.Min - 2' error CS0221: Constant value '-32770' cannot be converted to a 'S16' (use 'unchecked' syntax to override)"
,
"'U16.Min - 2' error CS0221: Constant value '-2' cannot be converted to a 'U16' (use 'unchecked' syntax to override)"
,
"'S32.Min - 2' error CS0220: The operation overflows at compile time in checked mode"
,
"'U32.Min - 2' error CS0220: The operation overflows at compile time in checked mode"
,
"'S64.Min - 2' error CS0220: The operation overflows at compile time in checked mode"
,
"'U64.Min - 2' error CS0220: The operation overflows at compile time in checked mode"
);
}"
;
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
(
// (32,11): error CS0221: Constant value '128' cannot be converted to a 'S8' (use 'unchecked' syntax to override)
// F(S8.Max + 1); // 128 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"S8.Max + 1"
).
WithArguments
(
"128"
,
"S8"
).
WithLocation
(
32
,
11
),
// (33,11): error CS0221: Constant value '256' cannot be converted to a 'U8' (use 'unchecked' syntax to override)
// F(U8.Max + 1); // 256 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"U8.Max + 1"
).
WithArguments
(
"256"
,
"U8"
).
WithLocation
(
33
,
11
),
// (34,11): error CS0221: Constant value '32768' cannot be converted to a 'S16' (use 'unchecked' syntax to override)
// F(S16.Max + 1); // 32768 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"S16.Max + 1"
).
WithArguments
(
"32768"
,
"S16"
).
WithLocation
(
34
,
11
),
// (35,11): error CS0221: Constant value '65536' cannot be converted to a 'U16' (use 'unchecked' syntax to override)
// F(U16.Max + 1); // 65536 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"U16.Max + 1"
).
WithArguments
(
"65536"
,
"U16"
).
WithLocation
(
35
,
11
),
// (36,11): error CS0220: The operation overflows at compile time in checked mode
// F(S32.Max + 1); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"S32.Max + 1"
).
WithLocation
(
36
,
11
),
// (37,11): error CS0220: The operation overflows at compile time in checked mode
// F(U32.Max + 1); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"U32.Max + 1"
).
WithLocation
(
37
,
11
),
// (38,11): error CS0220: The operation overflows at compile time in checked mode
// F(S64.Max + 1); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"S64.Max + 1"
).
WithLocation
(
38
,
11
),
// (39,11): error CS0220: The operation overflows at compile time in checked mode
// F(U64.Max + 1); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"U64.Max + 1"
).
WithLocation
(
39
,
11
),
// (42,11): error CS0221: Constant value '129' cannot be converted to a 'S8' (use 'unchecked' syntax to override)
// F(2 + S8.Max); // 129 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"2 + S8.Max"
).
WithArguments
(
"129"
,
"S8"
).
WithLocation
(
42
,
11
),
// (43,11): error CS0221: Constant value '257' cannot be converted to a 'U8' (use 'unchecked' syntax to override)
// F(2 + U8.Max); // 257 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"2 + U8.Max"
).
WithArguments
(
"257"
,
"U8"
).
WithLocation
(
43
,
11
),
// (44,11): error CS0221: Constant value '32769' cannot be converted to a 'S16' (use 'unchecked' syntax to override)
// F(2 + S16.Max); // 32769 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"2 + S16.Max"
).
WithArguments
(
"32769"
,
"S16"
).
WithLocation
(
44
,
11
),
// (45,11): error CS0221: Constant value '65537' cannot be converted to a 'U16' (use 'unchecked' syntax to override)
// F(2 + U16.Max); // 65537 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"2 + U16.Max"
).
WithArguments
(
"65537"
,
"U16"
).
WithLocation
(
45
,
11
),
// (46,11): error CS0220: The operation overflows at compile time in checked mode
// F(2 + S32.Max); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"2 + S32.Max"
).
WithLocation
(
46
,
11
),
// (47,11): error CS0220: The operation overflows at compile time in checked mode
// F(2 + U32.Max); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"2 + U32.Max"
).
WithLocation
(
47
,
11
),
// (48,11): error CS0220: The operation overflows at compile time in checked mode
// F(2 + S64.Max); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"2 + S64.Max"
).
WithLocation
(
48
,
11
),
// (49,11): error CS0220: The operation overflows at compile time in checked mode
// F(2 + U64.Max); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"2 + U64.Max"
).
WithLocation
(
49
,
11
),
// (53,11): error CS0221: Constant value '-1' cannot be converted to a 'byte' (use 'unchecked' syntax to override)
// F(U8.Min - U8.MinPlusOne); // -1 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"U8.Min - U8.MinPlusOne"
).
WithArguments
(
"-1"
,
"byte"
).
WithLocation
(
53
,
11
),
// (55,11): error CS0221: Constant value '-1' cannot be converted to a 'ushort' (use 'unchecked' syntax to override)
// F(U16.Min - U16.MinPlusOne); // -1 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"U16.Min - U16.MinPlusOne"
).
WithArguments
(
"-1"
,
"ushort"
).
WithLocation
(
55
,
11
),
// (57,11): error CS0220: The operation overflows at compile time in checked mode
// F(U32.Min - U32.MinPlusOne); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"U32.Min - U32.MinPlusOne"
).
WithLocation
(
57
,
11
),
// (59,11): error CS0220: The operation overflows at compile time in checked mode
// F(U64.Min - U64.MinPlusOne); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"U64.Min - U64.MinPlusOne"
).
WithLocation
(
59
,
11
),
// (62,11): error CS0221: Constant value '-255' cannot be converted to a 'sbyte' (use 'unchecked' syntax to override)
// F(S8.Min - S8.Max); // -255 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"S8.Min - S8.Max"
).
WithArguments
(
"-255"
,
"sbyte"
).
WithLocation
(
62
,
11
),
// (63,11): error CS0221: Constant value '-255' cannot be converted to a 'byte' (use 'unchecked' syntax to override)
// F(U8.Min - U8.Max); // -255 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"U8.Min - U8.Max"
).
WithArguments
(
"-255"
,
"byte"
).
WithLocation
(
63
,
11
),
// (64,11): error CS0221: Constant value '-65535' cannot be converted to a 'short' (use 'unchecked' syntax to override)
// F(S16.Min - S16.Max); // -65535 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"S16.Min - S16.Max"
).
WithArguments
(
"-65535"
,
"short"
).
WithLocation
(
64
,
11
),
// (65,11): error CS0221: Constant value '-65535' cannot be converted to a 'ushort' (use 'unchecked' syntax to override)
// F(U16.Min - U16.Max); // -65535 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"U16.Min - U16.Max"
).
WithArguments
(
"-65535"
,
"ushort"
).
WithLocation
(
65
,
11
),
// (66,11): error CS0220: The operation overflows at compile time in checked mode
// F(S32.Min - S32.Max); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"S32.Min - S32.Max"
).
WithLocation
(
66
,
11
),
// (67,11): error CS0220: The operation overflows at compile time in checked mode
// F(U32.Min - U32.Max); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"U32.Min - U32.Max"
).
WithLocation
(
67
,
11
),
// (68,11): error CS0220: The operation overflows at compile time in checked mode
// F(S64.Min - S64.Max); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"S64.Min - S64.Max"
).
WithLocation
(
68
,
11
),
// (69,11): error CS0220: The operation overflows at compile time in checked mode
// F(U64.Min - U64.Max); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"U64.Min - U64.Max"
).
WithLocation
(
69
,
11
),
// (72,11): error CS0221: Constant value '255' cannot be converted to a 'sbyte' (use 'unchecked' syntax to override)
// F(S8.Max - S8.Min); // 255 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"S8.Max - S8.Min"
).
WithArguments
(
"255"
,
"sbyte"
).
WithLocation
(
72
,
11
),
// (74,11): error CS0221: Constant value '65535' cannot be converted to a 'short' (use 'unchecked' syntax to override)
// F(S16.Max - S16.Min); // 65535 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"S16.Max - S16.Min"
).
WithArguments
(
"65535"
,
"short"
).
WithLocation
(
74
,
11
),
// (76,11): error CS0220: The operation overflows at compile time in checked mode
// F(S32.Max - S32.Min); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"S32.Max - S32.Min"
).
WithLocation
(
76
,
11
),
// (78,11): error CS0220: The operation overflows at compile time in checked mode
// F(S64.Max - S64.Min); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"S64.Max - S64.Min"
).
WithLocation
(
78
,
11
),
// (82,11): error CS0221: Constant value '-130' cannot be converted to a 'S8' (use 'unchecked' syntax to override)
// F(S8.Min - 2); // -130 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"S8.Min - 2"
).
WithArguments
(
"-130"
,
"S8"
).
WithLocation
(
82
,
11
),
// (83,11): error CS0221: Constant value '-2' cannot be converted to a 'U8' (use 'unchecked' syntax to override)
// F(U8.Min - 2); // -2 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"U8.Min - 2"
).
WithArguments
(
"-2"
,
"U8"
).
WithLocation
(
83
,
11
),
// (84,11): error CS0221: Constant value '-32770' cannot be converted to a 'S16' (use 'unchecked' syntax to override)
// F(S16.Min - 2); // -32770 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"S16.Min - 2"
).
WithArguments
(
"-32770"
,
"S16"
).
WithLocation
(
84
,
11
),
// (85,11): error CS0221: Constant value '-2' cannot be converted to a 'U16' (use 'unchecked' syntax to override)
// F(U16.Min - 2); // -2 cannot be converted to ...
Diagnostic
(
ErrorCode
.
ERR_ConstOutOfRangeChecked
,
"U16.Min - 2"
).
WithArguments
(
"-2"
,
"U16"
).
WithLocation
(
85
,
11
),
// (86,11): error CS0220: The operation overflows at compile time in checked mode
// F(S32.Min - 2); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"S32.Min - 2"
).
WithLocation
(
86
,
11
),
// (87,11): error CS0220: The operation overflows at compile time in checked mode
// F(U32.Min - 2); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"U32.Min - 2"
).
WithLocation
(
87
,
11
),
// (88,11): error CS0220: The operation overflows at compile time in checked mode
// F(S64.Min - 2); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"S64.Min - 2"
).
WithLocation
(
88
,
11
),
// (89,11): error CS0220: The operation overflows at compile time in checked mode
// F(U64.Min - 2); // overflows at compile time in checked mode
Diagnostic
(
ErrorCode
.
ERR_CheckedOverflow
,
"U64.Min - 2"
).
WithLocation
(
89
,
11
));
}
[
Fact
,
WorkItem
(
528727
,
"DevDiv"
)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录