Skip to content

Commit 00ec825

Browse files
committed
fix: Fix throwing an exception on half typed variable definition
Closes #1079 Signed-off-by: Anton Grigorev <[email protected]>
1 parent 695ba21 commit 00ec825

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

server/src/main/java/org/eclipse/lsp/cobol/core/visitor/CobolVisitor.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,13 @@ public List<Node> visitDataDescriptionEntryFormat2(DataDescriptionEntryFormat2Co
539539
.level(LEVEL_66)
540540
.levelLocality(getLevelLocality(ctx.LEVEL_NUMBER_66()))
541541
.variableNameAndLocality(extractNameAndLocality(ctx.entryName()))
542-
.statementLocality(retrieveRangeLocality(ctx, positions).orElse(null))
543-
.renamesClause(extractNameAndLocality(ctx.dataRenamesClause().dataName()));
544-
ofNullable(ctx.dataRenamesClause().thruDataName())
542+
.statementLocality(retrieveRangeLocality(ctx, positions).orElse(null));
543+
ofNullable(ctx.dataRenamesClause())
544+
.map(DataRenamesClauseContext::dataName)
545+
.map(this::extractNameAndLocality)
546+
.ifPresent(builder::renamesClause);
547+
ofNullable(ctx.dataRenamesClause())
548+
.map(DataRenamesClauseContext::thruDataName)
545549
.map(ThruDataNameContext::dataName)
546550
.map(this::extractNameAndLocality)
547551
.ifPresent(builder::renamesThruClause);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2021 Broadcom.
3+
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Broadcom, Inc. - initial API and implementation
13+
*
14+
*/
15+
package org.eclipse.lsp.cobol.usecases;
16+
17+
import com.google.common.collect.ImmutableList;
18+
import com.google.common.collect.ImmutableMap;
19+
import org.eclipse.lsp.cobol.service.delegates.validations.SourceInfoLevels;
20+
import org.eclipse.lsp.cobol.usecases.engine.UseCaseEngine;
21+
import org.eclipse.lsp4j.Diagnostic;
22+
import org.eclipse.lsp4j.DiagnosticSeverity;
23+
import org.junit.jupiter.api.Test;
24+
25+
/**
26+
* Test that not completely typed variable definition doesn't produce an exception.
27+
*/
28+
class TestHalfTypedVariableDefinition {
29+
private static final String TEXT =
30+
" Identification Division.\n"
31+
+ " Program-id. HELLO-WORLD.\n"
32+
+ " DATA DIVISION.\n"
33+
+ " WORKING-STORAGE SECTION.\n"
34+
+ " 01 {$*COD-RETOUR} PIC X{(|1}{66|2}{|3}";
35+
36+
@Test
37+
void test() {
38+
UseCaseEngine.runTest(TEXT, ImmutableList.of(), ImmutableMap.of(
39+
"1",
40+
new Diagnostic(null, "Extraneous input '(' expected {BINARY, BLANK, COMP, COMPUTATIONAL, "
41+
+ "COMPUTATIONAL-1, COMPUTATIONAL-2, COMPUTATIONAL-3, COMPUTATIONAL-4, COMPUTATIONAL-5, COMP-1, COMP-2, "
42+
+ "COMP-3, COMP-4, COMP-5, DISPLAY, DISPLAY-1, DYNAMIC, EXTERNAL, FUNCTION-POINTER, GLOBAL, GROUP-USAGE, "
43+
+ "INDEX, IS, JUST, JUSTIFIED, LEADING, NATIONAL, OBJECT, OCCURS, PACKED-DECIMAL, PIC, PICTURE, POINTER, "
44+
+ "POINTER-32, PROCEDURE-POINTER, REDEFINES, SIGN, SYNC, SYNCHRONIZED, TRAILING, USAGE, UTF-8, VALUE, "
45+
+ "VALUES, VOLATILE, '.', '.'2}",
46+
DiagnosticSeverity.Error, SourceInfoLevels.ERROR.getText()),
47+
"2",
48+
new Diagnostic(null, "No data definition entry found for rename",
49+
DiagnosticSeverity.Error, SourceInfoLevels.ERROR.getText()),
50+
"3",
51+
new Diagnostic(null, "Unexpected end of file",
52+
DiagnosticSeverity.Error, SourceInfoLevels.ERROR.getText())
53+
));
54+
}
55+
}

0 commit comments

Comments
 (0)