diff --git a/CHANGELOG.md b/CHANGELOG.md index 11e8d91..ad1ffa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,12 @@ # collections-intellij Changelog ## [Unreleased] +### Fixed +- Fixed recursive collection on variables with no types +- Fix higher order type provider when no types are possible ## [0.3.3] -### Fixed +### Fixed - Fixed recursive collection on std class ## [0.3.2] diff --git a/gradle.properties b/gradle.properties index a090339..12a610a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = dev.nybroe.collector pluginName = Collector -pluginVersion = 0.3.3 +pluginVersion = 0.3.4 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. diff --git a/src/main/kotlin/dev/nybroe/collector/Util.kt b/src/main/kotlin/dev/nybroe/collector/Util.kt index 4673547..3912234 100644 --- a/src/main/kotlin/dev/nybroe/collector/Util.kt +++ b/src/main/kotlin/dev/nybroe/collector/Util.kt @@ -56,7 +56,11 @@ fun PhpType.isCollection(project: Project): Boolean { } fun PhpType.isCollectionStrict(project: Project): Boolean { - return this.types.all { PhpType().add(it).isCollection(project) } + if (this.types.isEmpty()) { + return false + } + + return this.types.none { !PhpType().add(it).isCollection(project) } } fun PhpType.isHigherOrderCollection(project: Project): Boolean { diff --git a/src/main/kotlin/dev/nybroe/collector/types/HigherOrderTypeProvider.kt b/src/main/kotlin/dev/nybroe/collector/types/HigherOrderTypeProvider.kt index 3e9b870..2394355 100644 --- a/src/main/kotlin/dev/nybroe/collector/types/HigherOrderTypeProvider.kt +++ b/src/main/kotlin/dev/nybroe/collector/types/HigherOrderTypeProvider.kt @@ -59,8 +59,8 @@ class HigherOrderTypeProvider : PhpTypeProvider4 { val type = PhpIndex.getInstance(project) .getBySignature(signature.split('|')[0]) .map { it.type } - .reduce { acc, phpType -> acc.add(phpType) } - .global(project) + .reduceOrNull { acc, phpType -> acc.add(phpType) } + ?.global(project) if (type === null) return null diff --git a/src/test/kotlin/dev/nybroe/collector/inspections/CollectFunctionOnCollectionInspectionTest.kt b/src/test/kotlin/dev/nybroe/collector/inspections/CollectFunctionOnCollectionInspectionTest.kt index afd16a0..3bacc67 100644 --- a/src/test/kotlin/dev/nybroe/collector/inspections/CollectFunctionOnCollectionInspectionTest.kt +++ b/src/test/kotlin/dev/nybroe/collector/inspections/CollectFunctionOnCollectionInspectionTest.kt @@ -30,7 +30,11 @@ internal class CollectFunctionOnCollectionInspectionTest : InspectionTest() { doNotMatchTest("collect_on_union_collection_type") } - fun testCollectionOnStdObject_property() { + fun testCollectionOnStdObjectProperty() { doNotMatchTest("collect_on_stdClass_property") } + + fun testCollectionOnNoTypeVariable() { + doNotMatchTest("collect_on_no_type_variable") + } } diff --git a/src/test/resources/inspections/CollectFunctionInCollectionInspection/nonMatches/collect_on_no_type_variable.php b/src/test/resources/inspections/CollectFunctionInCollectionInspection/nonMatches/collect_on_no_type_variable.php new file mode 100644 index 0000000..cc8215c --- /dev/null +++ b/src/test/resources/inspections/CollectFunctionInCollectionInspection/nonMatches/collect_on_no_type_variable.php @@ -0,0 +1,5 @@ +