1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2025-12-08 02:43:24 +02:00

Merge pull request #983 from 1C-Company/feature/952-collection-item-types

#952 проверка добавления в типизированную коллекцию
This commit is contained in:
Dmitriy Marmyshev
2022-02-14 22:35:22 +03:00
committed by GitHub
5 changed files with 228 additions and 10 deletions

View File

@@ -0,0 +1,31 @@
// @strict-types
// Parameters:
// MapParamenter - Map of KeyAndValue:
// * Key - Number -
// * Value - Number -
Procedure NonComplaint(MapParamenter) Export
Array = new Array; // Array of Number
Array.Add("");
MapParamenter.Insert("",
False);
EndProcedure
// Parameters:
// MapParamenter - Map of KeyAndValue:
// * Key - Number -
// * Value - Number -
Procedure Complaint(MapParamenter) Export
Array = new Array; // Array of Number
Array.Add(10);
MapParamenter.Insert(10,
10);
EndProcedure

View File

@@ -0,0 +1,17 @@
// @strict-types
Procedure NonComplaint() Export
Complaint("1");
EndProcedure
// Parameters:
// Strings - Array
Procedure Complaint(Strings)
Complaint(Strings);
EndProcedure

View File

@@ -407,6 +407,34 @@ public class CommonModuleStrictTypesTest
}
/**
* Test of {@link InvocationParamIntersectionCheck} that invokable method parameter type intersects
* with caller type for collections with typed items.
*
* @throws Exception the exception
*/
@Test
public void testInvocationParamIntersectionCollectionItemCheck() throws Exception
{
String checkId = "invocation-parameter-type-intersect";
String resouceName = "invocation-parameter-type-intersect-collection-item";
Module module = updateAndGetModule(resouceName);
List<Marker> markers = getMarters(checkId, module);
assertEquals(3, markers.size());
Marker marker = markers.get(0);
assertEquals("10", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
marker = markers.get(1);
assertEquals("13", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
marker = markers.get(2);
assertEquals("12", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
}
/**
* Test of {@link InvocationParamIntersectionCheck} that invokable method parameter type intersects
* with caller type, and skip checking if method has default value parameters.
@@ -431,6 +459,30 @@ public class CommonModuleStrictTypesTest
}
/**
* Test of {@link InvocationParamIntersectionCheck} that invokable method parameter type intersects
* with caller type that is local method with documentation comment.
*
* @throws Exception the exception
*/
@Test
public void testInvocationParamIntersectionCheckLocalDocComment() throws Exception
{
String checkId = "invocation-parameter-type-intersect";
String resouceName = "invocation-parameter-type-intersect-local-doc-comment";
Module module = updateAndGetModule(resouceName);
List<Marker> markers = getMarters(checkId, module);
assertEquals(1, markers.size());
Marker marker = markers.get(0);
assertEquals("5", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
}
private IDtProject getProject()
{
return dtProject;
@@ -446,9 +498,9 @@ public class CommonModuleStrictTypesTest
return markers;
}
private Module updateAndGetModule(String checkId) throws CoreException, IOException
private Module updateAndGetModule(String resourceName) throws CoreException, IOException
{
try (InputStream in = getClass().getResourceAsStream(FOLDER + checkId + ".bsl"))
try (InputStream in = getClass().getResourceAsStream(FOLDER + resourceName + ".bsl"))
{
IFile file = getProject().getWorkspaceProject().getFile(COMMON_MODULE_FILE_NAME);
file.setContents(in, true, true, new NullProgressMonitor());