Bug #9963
Date literal issues
0%
Related issues
History
#1 Updated by Vladimir Tsichevski about 1 year ago
- Related to Bug #9906: Incorrect date parsing in FWD DATE(CHARACTER) implementation added
#2 Updated by Vladimir Tsichevski about 1 year ago
Consider the following ABL program:
DEFINE VARIABLE d1 AS DATE NO-UNDO INITIAL 01/03-. DEFINE VARIABLE d2 AS DATE NO-UNDO INITIAL 01022999. DEFINE VARIABLE d3 AS DATE NO-UNDO INITIAL "01/02/03abc". DEFINE VARIABLE d4 AS DATE NO-UNDO INITIAL "01/03-". DEFINE VARIABLE d5 AS DATE NO-UNDO INITIAL "01022999". DEFINE VARIABLE d6 AS DATE NO-UNDO INITIAL "abc". DEFINE VARIABLE d7 AS DATE NO-UNDO INITIAL abc. MESSAGE d1 d2 d3 d4 d5 d6 d7.
Compile this program in OE to r-code. Since compilation stops on the first error, comment out previous problematic lines (e.g., d6, d7) to test subsequent variables.
OE Behavior¶
d1: Correctly parsed as a date literal in MDY format, resulting in year=2025 (default), month=1, day=3.d2: Correctly parsed as a date literal with a special MMDDYYYY format, resulting in year=2999, month=1, day=2.d3: Correctly parsed as a date literal in MMDDYYYY format, resulting in year=2003, month=1, day=2.d4: Equivalent tod1.d5: Equivalent tod2.d6: Compilation fails with errors 196, 342, and 85.d7: Compilation fails with errors 198 and 247.
FWD Behavior¶
Convert the program with FWD (ensure the MESSAGE statement is included to avoid optimization):
d1: Recognized as aDATE_LITERALby the lexer, correctly converted, cleaned to "01/03" bydate.cleanFormattedDate(removing trailing "-"), generatingTypeFactory.date(date.fromLiteral("01/03")).d2: Recognized as aNUM_LITERALby the lexer, incorrectly converted toTypeFactory.date(1022999), causing Java compilation failure.d3: Recognized as aDATE_LITERAL, correctly converted, cleaned to "01/02/03" bydate.cleanFormattedDate(removing "abc"), generatingTypeFactory.date(date.fromLiteral("01/02/03")).d4: Equivalent tod1, correctly handled.d5: Equivalent tod2, incorrectly handled, causing Java compilation failure.d6: Recognized as aSTRING, incorrectly converted toTypeFactory.date("abc"), causing Java compilation failure.d7: Conversion fails with "unexpected token: abc".
Note: FWD pre-processes date literals with date.cleanFormattedDate to remove extra characters, which may not be necessary if parsing is handled correctly during conversion.
Runtime Issue in FWD¶
After removing uncompilable variables (d2, d5, d6, d7) and re-converting, running the program in FWD prints ? for d1 and d4 instead of the expected year=2025, month=1, day=3. This occurs due to incorrect date parsing in FWD at runtime.
Proposed Fixes for FWD Conversion¶
The following issues must be addressed in FWD conversion:
- Ensure correct recognition of date literals, or allow both number literals and strings to be treated as date literals in context.
- Implement a date parsing procedure during conversion to validate and convert literals to date components (month, day, year).
- Generate Java code using date creation based on components, e.g.,
date d1 = TypeFactory.date(new date(1, 3, 2025)), rather than relying on unparsed strings. - Avoid pre-processing literals with
date.cleanFormattedDate, as this becomes redundant with proper parsing. - The code must use the updated date parsing procedure (this already solved in #9906).
#3 Updated by Greg Shah about 1 year ago
- Related to Support #6860: lexer tests added
#4 Updated by Greg Shah about 1 year ago
Florin: Please add these cases to the lexer tests.
#5 Updated by Greg Shah about 1 year ago
- Related to Feature #1889: rework the date.java internal tests as real unit tests added
#6 Updated by Greg Shah 6 months ago
Florin added these tests to the ABLUnit lexer tests in the testcases revision 1750. For example, see tests/conversion/lexer/4gl_testcases/dates/valid/letters_in_date.p or tests/conversion/lexer/4gl_testcases/dates/valid/missing_year_date.p.
The failing cases are in ./4gl_testcases/dates/invalid/string_for_date.p and ./4gl_testcases/dates/invalid/invalid_date_letters.p.