Skip to content

Commit

Permalink
fix issue with typeParameters typeParameter and inheritance propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Aug 12, 2024
1 parent 957adb6 commit 70e5b5d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,22 @@ public ResultHolder getConstraint(@Nullable HaxeGenericResolver resolver) {
if (constraint != null) {
HaxeTypeOrAnonymous toa = constraint.getTypeOrAnonymous();
if (toa != null) {
if (null != toa.getType()) {
HaxeReferenceExpression reference = toa.getType().getReferenceExpression();
ResultHolder result = HaxeExpressionEvaluator.evaluate(reference, new HaxeExpressionEvaluatorContext(part), resolver).result;
HaxeType type = toa.getType();
if (null != type) {

ResultHolder result = HaxeTypeResolver.getTypeFromType(type);
if (!result.isUnknown()) {
return result;
}
else {
} else {
HaxeReferenceExpression reference = type.getReferenceExpression();
if (HaxeTypeResolver.isTypeParameter(reference)) {
// we dont want to resolve typeParameter constraints as the definition of this type parameter might need to inherit the type
return new ResultHolder(
SpecificHaxeClassReference.withoutGenerics(new HaxeClassReference(toa.getType().getText(), toa.getType(), true)));
SpecificHaxeClassReference.withoutGenerics(new HaxeClassReference(type.getText(), type, true)));
//return HaxeTypeResolver.getTypeFromTypeOrAnonymous(toa);
}
}
}

else {
} else {
// Anonymous struct for a constraint.
// TODO: Turn the anonymous structure into a ResolveResult.
return HaxeTypeResolver.getTypeFromTypeOrAnonymous(toa, resolver); //temp solution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static HaxeGenericResolver createInheritedClassResolver(HaxeClass inherit
HaxeGenericResolver localResolver) {

List<SpecificHaxeClassReference> path = new ArrayList<>();
findClasHierarchy(ownerClass, inheritedClass, path);
findClassHierarchy(ownerClass, inheritedClass, path);

Collections.reverse(path);
HaxeGenericResolver resolver = ownerClass.getMemberResolver(localResolver);
Expand All @@ -273,7 +273,7 @@ public static HaxeGenericResolver createInheritedClassResolver(HaxeClass inherit
return resolver;
}

private static boolean findClasHierarchy(HaxeClass from, HaxeClass to, List<SpecificHaxeClassReference> path) {
private static boolean findClassHierarchy(HaxeClass from, HaxeClass to, List<SpecificHaxeClassReference> path) {
HaxeClassModel fromModel = from.getModel();
if (fromModel.isTypedef()) {
SpecificHaxeClassReference reference = fromModel.getUnderlyingClassReference(new HaxeGenericResolver());
Expand All @@ -283,7 +283,7 @@ private static boolean findClasHierarchy(HaxeClass from, HaxeClass to, List<Spec
if (resolvedTypeDef != null) {
HaxeClass childClass = resolvedTypeDef.getHaxeClass();
if (childClass == to) return true;
if (childClass != null) return findClasHierarchy(childClass, to, path);
if (childClass != null) return findClassHierarchy(childClass, to, path);
}
}
}
Expand All @@ -295,7 +295,7 @@ private static boolean findClasHierarchy(HaxeClass from, HaxeClass to, List<Spec
if (childClass == to) {
return path.add(model.getSpecificHaxeClassReference());
} else {
if (findClasHierarchy(childClass, to, path)) {
if (findClassHierarchy(childClass, to, path)) {
path.add(model.getSpecificHaxeClassReference());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@ static public ResultHolder getTypeFromType(@NotNull HaxeType type, @Nullable Hax
}

static public ResultHolder getTypeFromType(@NotNull HaxeType type, @Nullable HaxeGenericResolver resolver, boolean useAssignHint) {
//System.out.println("Type:" + type);
//System.out.println("Type:" + type.getText());
if (resolver != null && !resolver.isEmpty()) {
ResultHolder resolve = resolver.resolve(type, useAssignHint);
if (resolve != null && !resolve.isUnknown()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.intellij.openapi.util.RecursionManager;
import com.intellij.plugins.haxe.lang.psi.*;
import com.intellij.plugins.haxe.lang.psi.impl.AbstractHaxeTypeDefImpl;
import com.intellij.plugins.haxe.lang.psi.impl.HaxeClassWrapperForTypeParameter;
import com.intellij.plugins.haxe.lang.psi.impl.HaxeTypeParameterMultiType;
import com.intellij.plugins.haxe.metadata.HaxeMetadataList;
import com.intellij.plugins.haxe.metadata.psi.HaxeMeta;
Expand Down Expand Up @@ -105,7 +106,13 @@ public static SpecificHaxeClassReference withGenerics(@NotNull HaxeClassReferenc
@Nullable
public HaxeClass getHaxeClass() {
if(clazz == null || !clazz.isValid()) {
clazz = this.getHaxeClassReference().getHaxeClass();
HaxeClassReference reference = this.getHaxeClassReference();
clazz = reference.getHaxeClass();
if(clazz == null && reference.isTypeParameter()) {
PsiElement element = reference.elementContext;
if(element instanceof HaxeType haxeType)
clazz = new HaxeClassWrapperForTypeParameter(element.getNode(), List.of(haxeType));
}
}
return clazz;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ReturnTypeGenerics<T> {
public static function staticGenericFn<T>(x:T)/*<# :T #>*/ {
return x;
}
//TODO need fix: incorrect typeParameter
public static function staticGenericFn2<T:ReturnTypeGenerics<String>>(x:T)/*<# :ReturnTypeGenerics<T> #>*/ {

public static function staticGenericFn2<T:ReturnTypeGenerics<String>>(x:T)/*<# :ReturnTypeGenerics<String> #>*/ {
return x;
}
}

0 comments on commit 70e5b5d

Please sign in to comment.