You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
swift-ci opened this issue
Dec 27, 2018
· 4 comments
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselfparserArea → compiler: The legacy C++ parser
I cannot call any member on an array literal containing only one floating point literal.
Here's my SSCCE:
print([1.2].count)
Expected result:
A new array containing only a Double with a value of 1.2 is created, and its count of 1 is printed
Actual result:
Compiler error is emitted:
main.swift:1:10: error: expected named member of numeric literal
print([1.2].count)
~~^
Notes:
I have confirmed that this issue does not occur with any of these following permutations, which lead me to the conclusion that this is a compiler bug and not an intended syntax disambiguation feature:
Array's sole element is an integer, string, nil, array, or dictionary literal
Array's sole element is an identifier instead of a literal
Array has more than one element
Array has less than one element
No member of the array is referenced
Float literal is the key andor value of a single-element dictionary literal
The text was updated successfully, but these errors were encountered:
// Therefore: x.0.1 is sub-tuple access, not x.float_literal
if (!isDigit(CurPtr[1]) || NextToken.is(tok::period))
// NextToken is the soon to be previous token// Therefore: x.0.1 is sub-tuple access, not x.float_literalif (!isDigit(CurPtr[1]) || NextToken.is(tok::period))
return formToken(tok::integer_literal, TokStart);
In parsing [1.2].count , after the backtracking, the Lexer is at 1, but unfortunately, NextToken is actually tok::period (which is the dot after ]) because backtracking doesn't restore NextToken state.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselfparserArea → compiler: The legacy C++ parser
Environment
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin17.7.0
Xcode Version 10.1 (10B61)
macOS Version 10.13.6 (17G4015)
Additional Detail from JIRA
md5: 531753d303555d7338e2b36a3bb85c86
Issue Description:
I cannot call any member on an array literal containing only one floating point literal.
Here's my SSCCE:
Expected result:
A new array containing only a
Double
with a value of1.2
is created, and its count of1
is printedActual result:
Compiler error is emitted:
Notes:
I have confirmed that this issue does not occur with any of these following permutations, which lead me to the conclusion that this is a compiler bug and not an intended syntax disambiguation feature:
Array's sole element is an integer, string, nil, array, or dictionary literal
Array's sole element is an identifier instead of a literal
Array has more than one element
Array has less than one element
No member of the array is referenced
Float literal is the key andor value of a single-element dictionary literal
The text was updated successfully, but these errors were encountered: