Skip to content

Commit

Permalink
fix canAssign for anonymous structures and classes (check inherited c…
Browse files Browse the repository at this point in the history
…lass members)
  • Loading branch information
m0rkeulv committed Jan 31, 2024
1 parent 25cd4f1 commit df8e3ec
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/main/java/com/intellij/plugins/haxe/lang/psi/HaxeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class HaxeResolver implements ResolveCache.AbstractResolver<HaxeReference
public static final int MAX_DEBUG_MESSAGE_LENGTH = 200;
public static final Key<Boolean> isExtensionKey = new Key<>("isExtensionKey");
public static final Key<String> typeHintKey = new Key<>("typeHint");
private static final Key<Boolean> skipCacheKey = new Key<>("skipCache");

//static { // Remove when finished debugging.
// LOG.setLevel(LogLevel.DEBUG);
Expand All @@ -83,6 +84,7 @@ public List<? extends PsiElement> resolve(@NotNull HaxeReference reference, bool

// Kill circular resolutions -- before checking the cache.
if (isResolving(reference)) {
reference.putUserData(skipCacheKey, Boolean.TRUE);
reportSkip(reference);
return EMPTY_LIST;
}
Expand Down Expand Up @@ -117,8 +119,17 @@ public List<? extends PsiElement> resolve(@NotNull HaxeReference reference, bool
}
}
}

return elements == null ? EMPTY_LIST : elements;
if (elements == null) {
// to avoid caching empty due to already being resolved we mark
// elements so we know if we want to cache as not found or just skip (null is not cached, empty list is cached)
if (reference.getUserData(skipCacheKey) == Boolean.TRUE) {
return null;
}else {
return EMPTY_LIST;
}
}else {
return elements;
}
}

//TODO until we have type hints everywhere we need to skip caching for those refrences that rely on typeHints
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/intellij/plugins/haxe/model/HaxeClassModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ public List<HaxeMemberModel> getMembers(@Nullable HaxeGenericResolver resolver)
members.addAll(getFields());
return members;
}
public List<HaxeMemberModel> getAllMembers(@Nullable HaxeGenericResolver resolver) {
final List<HaxeMemberModel> members = new ArrayList<>();
members.addAll(getAllMethods(resolver));
members.addAll(getFields());// TODO add get all ?
return members;
}

@NotNull
public List<HaxeMemberModel> getMembersSelf() {
Expand Down Expand Up @@ -542,6 +548,14 @@ public List<HaxeMethodModel> getMethods(@Nullable HaxeGenericResolver resolver)
}
return models;
}
public List<HaxeMethodModel> getAllMethods(@Nullable HaxeGenericResolver resolver) {
List<HaxeMethodModel> models = getAncestorMethods(resolver);
for (HaxeMethod method : haxeClass.getHaxeMethodsSelf(resolver)) {
models.add(method.getModel());
}

return models;
}

public List<HaxeMethodModel> getMethodsSelf(@Nullable HaxeGenericResolver resolver) {
List<HaxeMethodModel> models = new ArrayList<HaxeMethodModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,19 +481,19 @@ private static boolean containsAllMembers(SpecificHaxeClassReference to, Specifi

if (to == null || from == null) return false;

List<HaxeMemberModel> toMembers = to.getHaxeClassModel().getMembers(to.getGenericResolver());
List<HaxeMemberModel> fromMembers = from.getHaxeClassModel().getMembers(to.getGenericResolver());
List<HaxeMemberModel> toMembers = to.getHaxeClassModel().getAllMembers(to.getGenericResolver());
List<HaxeMemberModel> fromMembers = from.getHaxeClassModel().getAllMembers(to.getGenericResolver());
for (HaxeMemberModel member : toMembers) {
HaxeComponentName psi = member.getNamePsi();
// TODO type check
String name = member.getName();
// TODO type check parameter and return type
boolean memberExists;
if (member instanceof HaxeMethodModel methodModel){
memberExists = fromMembers.stream().filter(model -> model instanceof HaxeMethodModel)
.map(model -> (HaxeMethodModel) model)
.filter(mm -> methodModel.getParameters().size() == mm.getParameters().size())
.anyMatch(model -> model.getNamePsi().textMatches(psi.getText()));
.anyMatch(model -> model.getNamePsi().textMatches(name));
}else {
memberExists = fromMembers.stream().anyMatch(model -> model.getNamePsi().textMatches(psi.getText()));
memberExists = fromMembers.stream().anyMatch(model -> model.getNamePsi().textMatches(name));
}
if (!memberExists) return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class InitializeEnumMapWithMapLiteral {

// Errors below here...
t.mapv = <error descr="Incompatible type: Map<MyEnum, String> should be Map<EnumValue, String>">m</error>;
t.map = <error descr="Incompatible type: EnumValueMap<MyEnum, String> should be Map<MyEnum, String>">t.enummap</error>;
t.map = <error descr="Incompatible type: EnumValueMap<MyEnum, String> should be haxe.ds.Map<MyEnum, String>">t.enummap</error>;
t.mapv = <error descr="Incompatible type: EnumValueMap<MyEnum, String> should be Map<EnumValue, String>">t.enummap</error>;
t.enummap = <error descr="Incompatible type: Map<EnumValue, String> should be EnumValueMap<MyEnum, String>">t.mapv</error>;
t.map = <error descr="Incompatible type: Map<EnumValue, String> should be Map<MyEnum, String>">t.mapv</error>;
t.map = <error descr="Incompatible type: Map<EnumValue, String> should be haxe.ds.Map<MyEnum, String>">t.mapv</error>;
t.mapv = <error descr="Incompatible type: Map<MyEnum, String> should be Map<EnumValue, String>">t.map</error>;
}

Expand Down

0 comments on commit df8e3ec

Please sign in to comment.