diff --git a/src/main/kotlin/com/vk/kphpstorm/exphptype/ExPhpTypeInstance.kt b/src/main/kotlin/com/vk/kphpstorm/exphptype/ExPhpTypeInstance.kt index f5bf861..33512c4 100644 --- a/src/main/kotlin/com/vk/kphpstorm/exphptype/ExPhpTypeInstance.kt +++ b/src/main/kotlin/com/vk/kphpstorm/exphptype/ExPhpTypeInstance.kt @@ -14,8 +14,11 @@ class ExPhpTypeInstance(val fqn: String) : ExPhpType { override fun toString() = fqn override fun toHumanReadable(expr: PhpPsiElement) = - if (fqn.startsWith('\\')) PhpCodeInsightUtil.createQualifiedName(PhpCodeInsightUtil.findScopeForUseOperator(expr)!!, fqn) - else fqn + if (fqn.startsWith('\\')) PhpCodeInsightUtil.createQualifiedName( + PhpCodeInsightUtil.findScopeForUseOperator(expr)!!, + fqn + ) + else fqn override fun toPhpType(): PhpType { return PhpType().add(fqn) @@ -28,11 +31,43 @@ class ExPhpTypeInstance(val fqn: String) : ExPhpType { override fun instantiateTemplate(nameMap: Map): ExPhpType { return nameMap[fqn] ?: this } + private fun canBeAssigned(l: ExPhpTypeInstance, r: ExPhpTypeInstance) = with(ExPhpType.Companion) { + when { + l === ExPhpTypeInstance(KphpPrimitiveTypes.OBJECT) -> r === ExPhpTypeInstance(KphpPrimitiveTypes.OBJECT) + else -> false // not supposed to happen + } + } override fun isAssignableFrom(rhs: ExPhpType, project: Project): Boolean = when (rhs) { is ExPhpTypeAny -> true is ExPhpTypePipe -> rhs.isAssignableTo(this, project) - is ExPhpTypeNullable -> isAssignableFrom(rhs.inner, project) + is ExPhpTypeNullable -> { + /* if(this === ExPhpType.OBJECT){ + + } + rhs === ExPhpType.OBJECT || rhs === ExPhpType.NULL*/ + /*ExPhpType.OBJECT + val OBJECT = ExPhpTypeInstance(KphpPrimitiveTypes.OBJECT) + rhs === OBJECT || rhs === ExPhpType.NULL*/ + /*if(this as ExPhpTypeNullable && rhs is ExPhpTypeNullable){ + false + }*/ + false + /*val t = canBeAssigned(this, ExPhpTypeInstance(KphpPrimitiveTypes.NULL)) + if( this === ExPhpTypeInstance(KphpPrimitiveTypes.OBJECT)){ + rhs === ExPhpTypeInstance(KphpPrimitiveTypes.NULL) + }else{ + isAssignableFrom(rhs.inner, project) + }*/ + /* canBeAssigned(this, ExPhpTypeInstance(KphpPrimitiveTypes.NULL)) + val t = this.fqn + if (rhs.toString() != fqn) { + false + } else { + isAssignableFrom(rhs.inner, project) + }*/ + } + is ExPhpTypePrimitive -> rhs === ExPhpType.NULL || rhs === ExPhpType.OBJECT // rhs can be assigned if: rhs == lhs or rhs is child of lhs (no matter, lhs is interface or class) diff --git a/src/main/kotlin/com/vk/kphpstorm/exphptype/ExPhpTypeNullable.kt b/src/main/kotlin/com/vk/kphpstorm/exphptype/ExPhpTypeNullable.kt index 2c281fd..d147941 100644 --- a/src/main/kotlin/com/vk/kphpstorm/exphptype/ExPhpTypeNullable.kt +++ b/src/main/kotlin/com/vk/kphpstorm/exphptype/ExPhpTypeNullable.kt @@ -29,6 +29,7 @@ class ExPhpTypeNullable(val inner: ExPhpType) : ExPhpType { is ExPhpTypePipe -> rhs.isAssignableTo(this, project) is ExPhpTypeNullable -> inner.isAssignableFrom(rhs.inner, project) is ExPhpTypePrimitive -> rhs === ExPhpType.NULL || inner.isAssignableFrom(rhs, project) + is ExPhpTypeInstance -> false else -> inner.isAssignableFrom(rhs, project) } } diff --git a/src/main/kotlin/com/vk/kphpstorm/inspections/KphpParameterTypeMismatchInspection.kt b/src/main/kotlin/com/vk/kphpstorm/inspections/KphpParameterTypeMismatchInspection.kt index 3d59633..48224f2 100644 --- a/src/main/kotlin/com/vk/kphpstorm/inspections/KphpParameterTypeMismatchInspection.kt +++ b/src/main/kotlin/com/vk/kphpstorm/inspections/KphpParameterTypeMismatchInspection.kt @@ -76,6 +76,7 @@ class KphpParameterTypeMismatchInspection : PhpInspection() { val callType = PsiToExPhpType.getTypeOfExpr(callParam, project) ?: continue val argType = PsiToExPhpType.getArgumentDeclaredType(fArg, project) ?: continue + val test = !argType.isAssignableFrom(callType, project) if (!argType.isAssignableFrom(callType, project) && needsReporting(f)) { holder.registerProblem(callParam, "Can't pass '${callType.toHumanReadable(call)}' to '${argType.toHumanReadable(call)}' \$${fArg.name}", ProblemHighlightType.GENERIC_ERROR_OR_WARNING) }