From 851033086146f3cde76f623fe6e34e14cf68afe2 Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Thu, 25 Jan 2024 01:22:26 +0100 Subject: [PATCH] fix trace argument count issue and null/ typedef resolve for call expression annotator. --- CHANGELOG.md | 8 +++--- gradle.properties | 2 +- .../HaxeCallExpressionAnnotator.java | 27 +++++++++++++++++++ .../model/type/HaxeExpressionEvaluator.java | 9 ++++--- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a50a7f1..c5380e60c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,9 @@ # Changelog -## 1.4.24 -* Improved how function types where resolved -* Improved how call expressions with function types where checked. -## 1.4.23 +## 1.4.25 +* Improved: how function types where resolved +* Improved: how call expressions with function types where checked. +* Fixed: now resolving values from Null and typeDef when checking if field is callable * Fixed: typedefs of function types should now resolve correctly * Fixed: Introduce variable feature for introduce key-value intention * Fixed: Issue where members of anonymous structures using type-parameters did not resolve. diff --git a/gradle.properties b/gradle.properties index 6098bf241..eecc7b872 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ pluginName = Haxe Toolkit Support pluginRepositoryUrl = https://github.com/HaxeFoundation/intellij-haxe # SemVer format -> https://semver.org -pluginVersion = 1.4.24 +pluginVersion = 1.4.25 # IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties platformType = IU diff --git a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeCallExpressionAnnotator.java b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeCallExpressionAnnotator.java index 443e3f127..aa8c95ec5 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeCallExpressionAnnotator.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeCallExpressionAnnotator.java @@ -4,6 +4,7 @@ import com.intellij.lang.annotation.Annotator; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.plugins.haxe.lang.psi.*; +import com.intellij.plugins.haxe.model.FullyQualifiedInfo; import com.intellij.plugins.haxe.model.HaxeClassModel; import com.intellij.plugins.haxe.model.type.*; import com.intellij.psi.PsiElement; @@ -92,6 +93,22 @@ else if (classReference.isTypeParameter()) { } }else { SpecificTypeReference typeReference = type.getType(); + + if (type.getType().isNullType()) { + // unwrap null and check for function or callable + ResultHolder specific = type.getClassType().getSpecifics()[0]; + SpecificTypeReference specificType = specific.getType(); + if (specific.isTypeDef()) { + specificType = specific.getClassType().fullyResolveTypeDefReference(); + } + if (specificType instanceof SpecificFunctionReference) { + return; + }else if(specificType instanceof SpecificHaxeClassReference classReference){ + if (classReference.getHaxeClassModel() != null) { + if (classReference.getHaxeClassModel().isCallable()) return; + } + } + } // if not enum value constructor or dynamic, show error if (!type.isEnumValueType() && !type.isDynamic() && !type.isUnknown()) { // TODO bundle @@ -102,6 +119,7 @@ else if (classReference.isTypeParameter()) { } } else if (resolved instanceof HaxeMethod method) { + if (isTrace(method))return; CallExpressionValidation validation = checkMethodCall(expression, method); createErrorAnnotations(validation, holder); } @@ -113,6 +131,15 @@ else if (resolved instanceof HaxeMethod method) { } } + // the trace method in std does not have rest arg so we ignore it + private static boolean isTrace(HaxeMethod method) { + FullyQualifiedInfo info = method.getModel().getQualifiedInfo(); + if (info == null) return false; + return info.className.equals("Log") + && info.packagePath.equals("haxe") + && info.memberName.equals("trace"); + } + private void createErrorAnnotations(@NotNull CallExpressionValidation validation, @NotNull AnnotationHolder holder) { validation.errors.forEach(record -> holder.newAnnotation(HighlightSeverity.ERROR, record.message()) .range(record.range()) diff --git a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java index d6d8777b7..58ec29598 100644 --- a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java +++ b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java @@ -988,14 +988,16 @@ else if (subelement instanceof AbstractHaxeNamedComponent namedComponent) { ArrayList keyReferences = new ArrayList<>(initializers.size()); ArrayList valueReferences = new ArrayList<>(initializers.size()); + HaxeGenericResolver resolverWithoutHint = resolver.withoutAssignHint(); for (HaxeExpression ex : initializers) { HaxeMapInitializerExpression fatArrow = (HaxeMapInitializerExpression)ex; - SpecificTypeReference keyType = handle(fatArrow.getFirstChild(), context, resolver).getType(); + + SpecificTypeReference keyType = handle(fatArrow.getFirstChild(), context, resolverWithoutHint).getType(); if (keyType instanceof SpecificEnumValueReference enumValueReference) { keyType = enumValueReference.getEnumClass(); } keyReferences.add(keyType); - SpecificTypeReference valueType = handle(fatArrow.getLastChild(), context, resolver).getType(); + SpecificTypeReference valueType = handle(fatArrow.getLastChild(), context, resolverWithoutHint).getType(); if (valueType instanceof SpecificEnumValueReference enumValueReference) { valueType = enumValueReference.getEnumClass(); } @@ -1032,7 +1034,8 @@ else if (subelement instanceof AbstractHaxeNamedComponent namedComponent) { boolean allConstants = true; if (list != null) { for (HaxeExpression expression : list.getExpressionList()) { - SpecificTypeReference type = handle(expression, context, resolver).getType(); + // dropping AssignHint as we are in an array so field type will include the array part. + SpecificTypeReference type = handle(expression, context, resolver.withoutAssignHint()).getType(); if (!type.isConstant()) { allConstants = false; } else {