From 0870c9fd1bf63f179aa8e4ee3d5a8bf2d8f71696 Mon Sep 17 00:00:00 2001 From: Dmitriy Marmyshev Date: Sat, 25 Jun 2022 15:45:50 +0300 Subject: [PATCH] =?UTF-8?q?992=20=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=20Par?= =?UTF-8?q?amSet=20=D1=81=20=D1=83=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=D0=BE=D0=B2=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ .../InvocationParamIntersectionCheck.java | 10 +++++-- ...ameter-type-intersect-select-param-set.bsl | 30 +++++++++++++++++++ .../itests/CommonModuleStrictTypesTest.java | 27 +++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tests/com.e1c.v8codestyle.bsl.itests/resources/strict/invocation-parameter-type-intersect-select-param-set.bsl diff --git a/CHANGELOG.md b/CHANGELOG.md index d148955c..3b056538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,8 @@ ### Исправленные ошибки +- Ложное срабатывание проверки: invocation-parameter-type-intersect - для методов с несколькими вариантами вызова + ## 0.2.0 diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/InvocationParamIntersectionCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/InvocationParamIntersectionCheck.java index 4f7afbcb..b7267a06 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/InvocationParamIntersectionCheck.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/InvocationParamIntersectionCheck.java @@ -241,9 +241,10 @@ public class InvocationParamIntersectionCheck Collection targetTypes = getDefaultTargetOrCollectionItemTypes(method, collectionItemTypes, parameterNumbers, isMap, i, inv); - boolean isIntersect = !targetTypes.isEmpty() && intersectTypeItem(targetTypes, sorceTypes, inv); + boolean isCollectionItemTypeEmpty = targetTypes.isEmpty(); + boolean isIntersect = !isCollectionItemTypeEmpty && intersectTypeItem(targetTypes, sorceTypes, inv); Parameter parameter = null; - for (Iterator iterator = paramSets.iterator(); !isIntersect && targetTypes.isEmpty() + for (Iterator iterator = paramSets.iterator(); !isIntersect && isCollectionItemTypeEmpty && iterator.hasNext();) { ParamSet paramSet = iterator.next(); @@ -297,6 +298,11 @@ public class InvocationParamIntersectionCheck } isIntersect = intersectTypeItem(targetTypes, sorceTypes, inv); + if (!isIntersect && !targetTypes.isEmpty()) + { + // if we don't match this ParamSet so will not use for other parameters + iterator.remove(); + } } if (!isIntersect && !targetTypes.isEmpty()) diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/strict/invocation-parameter-type-intersect-select-param-set.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/strict/invocation-parameter-type-intersect-select-param-set.bsl new file mode 100644 index 00000000..92a754d7 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/strict/invocation-parameter-type-intersect-select-param-set.bsl @@ -0,0 +1,30 @@ +// @strict-types + +// Parameters: +// TabularSection - TabularSection +Procedure NonComplaint(TabularSection) Export + + Filter = New Structure();; + Row = TabularSection.Unload(Filter, + 1); + +EndProcedure + +// Parameters: +// TabularSection - TabularSection +Procedure NonComplaint2(TabularSection) Export + + Row = TabularSection.Unload(1, + "LineNumber, Ref"); + +EndProcedure + +// Parameters: +// TabularSection - TabularSection +Procedure Complaint(TabularSection) Export + + Filter = New Structure();; + Row = TabularSection.Unload(Filter, + "LineNumber, Ref"); + +EndProcedure diff --git a/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/strict/check/itests/CommonModuleStrictTypesTest.java b/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/strict/check/itests/CommonModuleStrictTypesTest.java index 0f5d9343..213fe5b1 100644 --- a/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/strict/check/itests/CommonModuleStrictTypesTest.java +++ b/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/strict/check/itests/CommonModuleStrictTypesTest.java @@ -434,6 +434,33 @@ public class CommonModuleStrictTypesTest assertEquals(Set.of("10", "12", "13"), lines); } + /** + * Test of {@link InvocationParamIntersectionCheck} that invokable method parameter type intersects + * with method that has several ParamSets and should select correct ones. + * + * @throws Exception the exception + */ + @Test + public void testInvocationParamIntersectionSelectParamSet() throws Exception + { + + String checkId = "invocation-parameter-type-intersect"; + String resouceName = "invocation-parameter-type-intersect-select-param-set"; + + Module module = updateAndGetModule(resouceName); + + List markers = getMarters(checkId, module); + + assertEquals(2, markers.size()); + + Set lines = new HashSet<>(); + for (Marker marker : markers) + { + lines.add(marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY)); + } + assertEquals(Set.of("9", "17"), lines); + } + /** * Test of {@link InvocationParamIntersectionCheck} that invokable method parameter type intersects * with caller type, and skip checking if method has default value parameters.