1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2024-12-03 19:26:38 +02:00

Merge pull request #1048 from 1C-Company/bugfix/992-select-param-set

992 Корректный выбор ParamSet с учетом типов коллекций
This commit is contained in:
Dmitriy Marmyshev 2022-06-25 19:48:09 +03:00 committed by GitHub
commit 508d06a48f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 2 deletions

View File

@ -40,6 +40,8 @@
### Исправленные ошибки
- Ложное срабатывание проверки: invocation-parameter-type-intersect - для методов с несколькими вариантами вызова
## 0.2.0

View File

@ -241,9 +241,10 @@ public class InvocationParamIntersectionCheck
Collection<TypeItem> 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<ParamSet> iterator = paramSets.iterator(); !isIntersect && targetTypes.isEmpty()
for (Iterator<ParamSet> 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())

View File

@ -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

View File

@ -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<Marker> markers = getMarters(checkId, module);
assertEquals(2, markers.size());
Set<String> 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.