Skip to content

Commit

Permalink
fix trace argument count issue and null<T>/ typedef resolve for call …
Browse files Browse the repository at this point in the history
…expression annotator.
  • Loading branch information
m0rkeulv committed Jan 25, 2024
1 parent aca14fe commit 8510330
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<T> 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.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,6 +93,22 @@ else if (classReference.isTypeParameter()) {
}
}else {
SpecificTypeReference typeReference = type.getType();

if (type.getType().isNullType()) {
// unwrap null<T> 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
Expand All @@ -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);
}
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,14 +988,16 @@ else if (subelement instanceof AbstractHaxeNamedComponent namedComponent) {

ArrayList<SpecificTypeReference> keyReferences = new ArrayList<>(initializers.size());
ArrayList<SpecificTypeReference> 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();
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8510330

Please sign in to comment.