Skip to content

Commit

Permalink
Infer data type when variable is used as array index access (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusAmshove authored Dec 1, 2023
2 parents c8b4137 + d803a9e commit 59a49d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -642,4 +642,31 @@ void addAVariableToAGroupInAnImportedDataArea()
END-DEFINE
""");
}

@Test
void addAVariableWithInferredTypeWhenVariableIsUsedAsArrayAccess()
{
assertCodeActionWithTitle("Declare local variable #INDEX", "LIBONE", "MEINS.NSN", """
DEFINE DATA
LOCAL
1 #ARR (A10/1:*)
END-DEFINE
#ARR(#IN${}$DEX) := 'A'
END
""")
.fixes(ParserError.UNRESOLVED_REFERENCE.id())
.resultsApplied("""
DEFINE DATA
LOCAL
1 #INDEX (I4)
1 #ARR (A10/1:*)
END-DEFINE
#ARR(#INDEX) := 'A'
END
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public static Optional<IDataType> inferTypeForTokenInStatement(SyntaxToken token
return Optional.of(I4);
}

if (tokenNode.parent() instanceof IVariableReferenceNode) // Array access
{
return Optional.of(I4);
}

return Optional.empty();
}

Expand Down

0 comments on commit 59a49d2

Please sign in to comment.