Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TypeCobol.Analysis.Test/BasicCfgInstrs/CGM110.diag
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ Line 28256[8,37] <37, Warning, General> - Warning: Paragraph 'CGBCALAK-SYSPUNCH-
Line 28289[8,37] <37, Warning, General> - Warning: Paragraph 'CGBCALAK-SYSPUNCH-WSBA-SUITE' is empty
Line 28327[8,32] <37, Warning, General> - Warning: Paragraph 'CGBCALAK-SYSPUNCH-SUITE' is empty
Line 29421[13,18] <37, Warning, General> - Warning: a End statement is not aligned with the matching opening statement
Line 29550[20,71] <37, Warning, General> - Warning: Moving alphanumeric 'WS-CMM010-CODE-CADRAGE-JJ' to numeric 'WS-CMM010-CADR-BIN' declared with an USAGE may lead to unexpected results.
Line 29627[16,21] <37, Warning, General> - Warning: a End statement is not aligned with the matching opening statement
Line 29628[16,21] <37, Warning, General> - Warning: a End statement is not aligned with the matching opening statement
Line 29685[24,46] <37, Warning, General> - Warning: Moving alphanumeric 'WS-CMM010-CODE-CADRAGE-JJ' to numeric 'WS-CMM010-CADR-BIN' declared with an USAGE may lead to unexpected results.
Line 29772[12,17] <37, Warning, General> - Warning: "end-if" is missing
Line 29776[16,21] <37, Warning, General> - Warning: "end-if" is missing
Line 31035[21,26] <37, Warning, General> - Warning: a End statement is not aligned with the matching opening statement
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. Pgm.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 alpha pic X(03).
01 alpha2 pic X(03).

01 num1 pic 9(03).
01 num2 comp-1.
01 num3 comp-2.
01 num4 pic 9(03) comp-3.
01 num5 pic 9(03) comp-4.
01 num6 pic 9(03) comp-5.
01 num7 pic 9(03) packed-decimal.
01 num8 pic 9(03) binary.
01 num9 pic 9(03) comp.

PROCEDURE DIVISION.

* Ok
move alpha to alpha2
* Ok because num1 is an extended numeric
move alpha to num1
* Ok as it is not a numeric
move alpha to num2
* Ok as it is not a numeric
move alpha to num3

* Ko because it is a comp variable
move alpha to num4
* Ko because it is a comp variable
move alpha to num5
* Ko because it is a comp variable
move alpha to num6
* Ko because it is a comp variable
move alpha to num7
* Ko because it is a comp variable
move alpha to num8
* Ko because it is a comp variable
move alpha to num9

* Ok because it is a function
move FUNCTION WHEN-COMPILED to num4
* Ok because it is a function
move FUNCTION CURRENT-DATE to num4
* Ok because it is a function
move LENGTH alpha to num4
* Ok because it is a function
move LENGTH OF alpha to num4

GOBACK
.

END PROGRAM Pgm.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. Pgm.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 alpha pic X(03).
01 alpha2 pic X(03).

01 num1 pic 9(03).
01 num2 comp-1.
01 num3 comp-2.
01 num4 pic 9(03) comp-3.
01 num5 pic 9(03) comp-4.
01 num6 pic 9(03) comp-5.
01 num7 pic 9(03) packed-decimal.
01 num8 pic 9(03) binary.
01 num9 pic 9(03) comp.

PROCEDURE DIVISION.

* Ok
move alpha to alpha2
* Ok because num1 is an extended numeric
move alpha to num1
* Ok as it is not a numeric
move alpha to num2
* Ok as it is not a numeric
move alpha to num3

* Ko because it is a comp variable
Line 30[12,38] <37, Warning, General> - Warning: Moving alphanumeric 'alpha' to numeric 'num4' declared with an USAGE may lead to unexpected results.
move alpha to num4
* Ko because it is a comp variable
Line 32[12,38] <37, Warning, General> - Warning: Moving alphanumeric 'alpha' to numeric 'num5' declared with an USAGE may lead to unexpected results.
move alpha to num5
* Ko because it is a comp variable
Line 34[12,38] <37, Warning, General> - Warning: Moving alphanumeric 'alpha' to numeric 'num6' declared with an USAGE may lead to unexpected results.
move alpha to num6
* Ko because it is a comp variable
Line 36[12,38] <37, Warning, General> - Warning: Moving alphanumeric 'alpha' to numeric 'num7' declared with an USAGE may lead to unexpected results.
move alpha to num7
* Ko because it is a comp variable
Line 38[12,38] <37, Warning, General> - Warning: Moving alphanumeric 'alpha' to numeric 'num8' declared with an USAGE may lead to unexpected results.
move alpha to num8
* Ko because it is a comp variable
Line 40[12,38] <37, Warning, General> - Warning: Moving alphanumeric 'alpha' to numeric 'num9' declared with an USAGE may lead to unexpected results.
move alpha to num9

* Ok because it is a function
move FUNCTION WHEN-COMPILED to num4
* Ok because it is a function
move FUNCTION CURRENT-DATE to num4
* Ok because it is a function
move LENGTH alpha to num4
* Ok because it is a function
move LENGTH OF alpha to num4

GOBACK
.

END PROGRAM Pgm.
29 changes: 27 additions & 2 deletions TypeCobol/Compiler/Diagnostics/CrossChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,40 @@ public override bool Visit(Move move)
{
return true;
}

var senderIsAlphanumeric = false;
DataDefinition senderDataDefinition = null;
if (moveSimple.SendingVariable?.StorageArea?.Kind == StorageAreaKind.DataOrCondition
&& move.StorageAreaReadsDataDefinition?.TryGetValue(moveSimple.SendingVariable.StorageArea, out senderDataDefinition) == true)
{
senderIsAlphanumeric = senderDataDefinition.DataType == DataType.Alphanumeric;
}

foreach (var area in moveSimple.StorageAreaWrites)
{
var receiver = area.StorageArea;
if (receiver is FunctionCallResult)
if (receiver == null) continue;

if (receiver.Kind == StorageAreaKind.FunctionCallResult)
{
DiagnosticUtils.AddError(move, "MOVE: illegal <function call> after TO");
}
else if (senderIsAlphanumeric
&& receiver.Kind == StorageAreaKind.DataOrCondition
&& move.StorageAreaWritesDataDefinition != null
&& move.StorageAreaWritesDataDefinition.TryGetValue(receiver, out var receiverDataDefinition))
{
if (receiverDataDefinition.DataType == DataType.Numeric || receiverDataDefinition.DataType == DataType.NumericEdited)
{
if (receiverDataDefinition.Usage != null && receiverDataDefinition.Usage != DataUsage.None)
{
DiagnosticUtils.AddError(move, $"Moving alphanumeric '{senderDataDefinition.Name}' to numeric '{receiverDataDefinition.Name}' declared with an USAGE may lead to unexpected results.", code: MessageCode.Warning);
}
}
}
}
}


return true;
}

Expand Down