From a65913d5b1f3c7478c84c4e5fe70b652a8d44f39 Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Fri, 27 Oct 2023 17:10:08 +0200 Subject: [PATCH] avoid check usage when type is known for Literal Array --- .../model/type/HaxeExpressionEvaluator.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) 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 a34838288..7e266bdc9 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 @@ -1028,25 +1028,28 @@ else if (subelement instanceof AbstractHaxeNamedComponent namedComponent) { } } } - - ResultHolder elementTypeHolder = references.isEmpty() - ? SpecificTypeReference.getUnknown(element).createHolder() - : HaxeTypeUnifier.unify(references, element, suggestedType).withoutConstantValue().createHolder(); - - SpecificTypeReference result = SpecificHaxeClassReference.createArray(elementTypeHolder, element); - if (allConstants) result = result.withConstantValue(constants); - ResultHolder holder = result.createHolder(); - - // try to resolve typeParameter when we got empty literal array with declaration without typeTag - if (elementTypeHolder.isUnknown()) { - HaxePsiField declaringField = PsiTreeUtil.getParentOfType(element, HaxePsiField.class); - if (declaringField != null) { - ResultHolder searchResult = searchReferencesForTypeParameters(declaringField, context, resolver, holder); - if (!searchResult.isUnknown()) holder = searchResult; + // empty expression with type tag (var x:Array = []), no need to look for usage + if (references.isEmpty() && suggestedType != null && !suggestedType.isUnknown()) { + return SpecificHaxeClassReference.createArray(suggestedType.createHolder(), element).createHolder(); + } else { + ResultHolder elementTypeHolder = references.isEmpty() + ? SpecificTypeReference.getUnknown(element).createHolder() + : HaxeTypeUnifier.unify(references, element, suggestedType).withoutConstantValue().createHolder(); + + SpecificTypeReference result = SpecificHaxeClassReference.createArray(elementTypeHolder, element); + if (allConstants) result = result.withConstantValue(constants); + ResultHolder holder = result.createHolder(); + + // try to resolve typeParameter when we got empty literal array with declaration without typeTag + if (elementTypeHolder.isUnknown()) { + HaxePsiField declaringField = PsiTreeUtil.getParentOfType(element, HaxePsiField.class); + if (declaringField != null) { + ResultHolder searchResult = searchReferencesForTypeParameters(declaringField, context, resolver, holder); + if (!searchResult.isUnknown()) holder = searchResult; + } } - } - return holder; + } } if (element instanceof HaxePsiToken psiToken) {