Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
bbf380be
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,发现更多精彩内容 >>
提交
bbf380be
编写于
9月 27, 2017
作者:
A
Alireza Habibi
提交者:
Julien Couvreur
9月 27, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug when trailing and leading underscores are not the same (#22141)
Merging on behalf of @alrz. Thanks
上级
7ee07eac
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
15 deletion
+35
-15
src/Compilers/CSharp/Portable/Parser/Lexer.cs
src/Compilers/CSharp/Portable/Parser/Lexer.cs
+16
-15
src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalTests.cs
...ompilers/CSharp/Test/Syntax/LexicalAndXml/LexicalTests.cs
+11
-0
src/Compilers/VisualBasic/Test/Syntax/Scanner/ScannerTests.vb
...Compilers/VisualBasic/Test/Syntax/Scanner/ScannerTests.vb
+8
-0
未找到文件。
src/Compilers/CSharp/Portable/Parser/Lexer.cs
浏览文件 @
bbf380be
...
...
@@ -933,9 +933,8 @@ private bool ScanInteger()
}
// Allows underscores in integers, except at beginning for decimal and end
private
void
ScanNumericLiteralSingleInteger
(
ref
bool
underscoreInWrongPlace
,
ref
bool
usedUnderscore
,
bool
isHex
,
bool
isBinary
)
private
void
ScanNumericLiteralSingleInteger
(
ref
bool
underscoreInWrongPlace
,
ref
bool
usedUnderscore
,
ref
bool
firstCharWasUnderscore
,
bool
isHex
,
bool
isBinary
)
{
bool
firstCharWasUnderscore
=
false
;
if
(
TextWindow
.
PeekChar
()
==
'_'
)
{
if
(
isHex
||
isBinary
)
...
...
@@ -971,13 +970,7 @@ private void ScanNumericLiteralSingleInteger(ref bool underscoreInWrongPlace, re
TextWindow
.
AdvanceChar
();
}
if
(
firstCharWasUnderscore
)
{
CheckFeatureAvailability
(
MessageID
.
IDS_FeatureLeadingDigitSeparator
);
// No need for cascading feature error
usedUnderscore
=
false
;
}
else
if
(
lastCharWasUnderscore
)
if
(
lastCharWasUnderscore
)
{
underscoreInWrongPlace
=
true
;
}
...
...
@@ -998,6 +991,7 @@ private bool ScanNumericLiteral(ref TokenInfo info)
bool
hasLSuffix
=
false
;
bool
underscoreInWrongPlace
=
false
;
bool
usedUnderscore
=
false
;
bool
firstCharWasUnderscore
=
false
;
ch
=
TextWindow
.
PeekChar
();
if
(
ch
==
'0'
)
...
...
@@ -1020,7 +1014,7 @@ private bool ScanNumericLiteral(ref TokenInfo info)
{
// It's OK if it has no digits after the '0x' -- we'll catch it in ScanNumericLiteral
// and give a proper error then.
ScanNumericLiteralSingleInteger
(
ref
underscoreInWrongPlace
,
ref
usedUnderscore
,
isHex
,
isBinary
);
ScanNumericLiteralSingleInteger
(
ref
underscoreInWrongPlace
,
ref
usedUnderscore
,
ref
firstCharWasUnderscore
,
isHex
,
isBinary
);
if
((
ch
=
TextWindow
.
PeekChar
())
==
'L'
||
ch
==
'l'
)
{
...
...
@@ -1050,7 +1044,7 @@ private bool ScanNumericLiteral(ref TokenInfo info)
}
else
{
ScanNumericLiteralSingleInteger
(
ref
underscoreInWrongPlace
,
ref
usedUnderscore
,
isHex
:
false
,
isBinary
:
false
);
ScanNumericLiteralSingleInteger
(
ref
underscoreInWrongPlace
,
ref
usedUnderscore
,
ref
firstCharWasUnderscore
,
isHex
:
false
,
isBinary
:
false
);
if
(
this
.
ModeIs
(
LexerMode
.
DebuggerSyntax
)
&&
TextWindow
.
PeekChar
()
==
'#'
)
{
...
...
@@ -1071,7 +1065,7 @@ private bool ScanNumericLiteral(ref TokenInfo info)
_builder
.
Append
(
ch
);
TextWindow
.
AdvanceChar
();
ScanNumericLiteralSingleInteger
(
ref
underscoreInWrongPlace
,
ref
usedUnderscore
,
isHex
:
false
,
isBinary
:
false
);
ScanNumericLiteralSingleInteger
(
ref
underscoreInWrongPlace
,
ref
usedUnderscore
,
ref
firstCharWasUnderscore
,
isHex
:
false
,
isBinary
:
false
);
}
else
if
(
_builder
.
Length
==
0
)
{
...
...
@@ -1102,7 +1096,7 @@ private bool ScanNumericLiteral(ref TokenInfo info)
}
else
{
ScanNumericLiteralSingleInteger
(
ref
underscoreInWrongPlace
,
ref
usedUnderscore
,
isHex
:
false
,
isBinary
:
false
);
ScanNumericLiteralSingleInteger
(
ref
underscoreInWrongPlace
,
ref
usedUnderscore
,
ref
firstCharWasUnderscore
,
isHex
:
false
,
isBinary
:
false
);
}
}
...
...
@@ -1174,7 +1168,11 @@ private bool ScanNumericLiteral(ref TokenInfo info)
{
this
.
AddError
(
MakeError
(
start
,
TextWindow
.
Position
-
start
,
ErrorCode
.
ERR_InvalidNumber
));
}
if
(
usedUnderscore
)
else
if
(
firstCharWasUnderscore
)
{
CheckFeatureAvailability
(
MessageID
.
IDS_FeatureLeadingDigitSeparator
);
}
else
if
(
usedUnderscore
)
{
CheckFeatureAvailability
(
MessageID
.
IDS_FeatureDigitSeparator
);
}
...
...
@@ -1198,7 +1196,10 @@ private bool ScanNumericLiteral(ref TokenInfo info)
default
:
if
(
string
.
IsNullOrEmpty
(
valueText
))
{
this
.
AddError
(
MakeError
(
ErrorCode
.
ERR_InvalidNumber
));
if
(!
underscoreInWrongPlace
)
{
this
.
AddError
(
MakeError
(
ErrorCode
.
ERR_InvalidNumber
));
}
val
=
0
;
//safe default
}
else
...
...
src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalTests.cs
浏览文件 @
bbf380be
...
...
@@ -2815,6 +2815,17 @@ public void TestNumericWithBadUnderscores()
Assert
.
Equal
(
"error CS1013: Invalid number"
,
errors
[
0
].
ToString
(
EnsureEnglishUICulture
.
PreferredOrNull
));
Assert
.
Equal
(
text
,
token
.
Text
);
text
=
"0x_2_"
;
token
=
LexToken
(
text
,
_options72
);
Assert
.
NotNull
(
token
);
Assert
.
Equal
(
SyntaxKind
.
NumericLiteralToken
,
token
.
Kind
());
errors
=
token
.
Errors
();
Assert
.
Equal
(
1
,
errors
.
Length
);
Assert
.
Equal
((
int
)
ErrorCode
.
ERR_InvalidNumber
,
errors
[
0
].
Code
);
Assert
.
Equal
(
"error CS1013: Invalid number"
,
errors
[
0
].
ToString
(
EnsureEnglishUICulture
.
PreferredOrNull
));
Assert
.
Equal
(
text
,
token
.
Text
);
text
=
"1E+_2"
;
token
=
LexToken
(
text
,
_options72
);
...
...
src/Compilers/VisualBasic/Test/Syntax/Scanner/ScannerTests.vb
浏览文件 @
bbf380be
...
...
@@ -1298,6 +1298,14 @@ End If]]>.Value,
Assert
.
Equal
(
1
,
errors
.
Count
)
Assert
.
Equal
(
30035
,
errors
.
First
().
Code
)
Assert
.
Equal
(
0
,
CInt
(
tk
.
Value
))
Str
=
"&H_2_"
tk
=
ScanOnce
(
Str
)
Assert
.
Equal
(
SyntaxKind
.
IntegerLiteralToken
,
tk
.
Kind
)
errors
=
tk
.
Errors
()
Assert
.
Equal
(
1
,
errors
.
Count
)
Assert
.
Equal
(
30035
,
errors
.
First
().
Code
)
Assert
.
Equal
(
0
,
CInt
(
tk
.
Value
))
End
Sub
<
Fact
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录