Skip to content

Commit

Permalink
Nullpointer fix, fix typedef + Null<>T resolve, canassign move dynami…
Browse files Browse the repository at this point in the history
…c check after typdef/null resolve
  • Loading branch information
m0rkeulv committed Feb 7, 2024
1 parent 9bc4119 commit 8a35ede
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1560,70 +1560,76 @@ public static ResultHolder searchReferencesForTypeParameters(final HaxePsiField
}
if (expression.getParent() instanceof HaxeArrayAccessExpression arrayAccessExpression) {
// try to find setter first if that fails try getter
HaxeNamedComponent arrayAccessSetter = classType.getHaxeClass().findArrayAccessSetter(resolver);
if (arrayAccessSetter instanceof HaxeMethodDeclaration methodDeclaration) {
HaxeMethodModel methodModel = methodDeclaration.getModel();
// make sure we are using class level typeParameters (and not method level)
if (methodModel.getGenericParams().isEmpty()) {
List<HaxeParameterModel> parameters = methodModel.getParameters();

HaxeTypeTag keyParamPsi = parameters.get(0).getTypeTagPsi();
HaxeTypeTag valueParamPsi = parameters.get(1).getTypeTagPsi();


@NotNull String[] specificNames = classResolver.names();
for (int i = 0; i < specificNames.length; i++) {
String keyPsiName = keyParamPsi.getTypeOrAnonymous().getType().getText();
// key
if (keyPsiName.equals(specificNames[i])) {
HaxeExpression keyExpression = arrayAccessExpression.getExpressionList().get(1);
ResultHolder handle = handle(keyExpression, context, resolver);
if (type.getSpecifics()[i].isUnknown()) {
type.getSpecifics()[i] = handle;
}else {
ResultHolder unified = HaxeTypeUnifier.unify(handle, type.getSpecifics()[i]);
type.getSpecifics()[i] = unified;
}
}
// value
if (arrayAccessExpression.getParent() instanceof HaxeBinaryExpression binaryExpression) {
String valuePsiName = valueParamPsi.getTypeOrAnonymous().getType().getText();
if (valuePsiName.equals(specificNames[i])) {
HaxeExpression keyExpression = binaryExpression.getExpressionList().get(1);
ResultHolder handle = handle(keyExpression, context, resolver);
if (type.getSpecifics()[i].isUnknown()) {
type.getSpecifics()[i] = handle;
}else {
ResultHolder unified = HaxeTypeUnifier.unify(handle, type.getSpecifics()[i]);
type.getSpecifics()[i] = unified;
}
}
}
}
}
} else {
HaxeNamedComponent arrayAccessGetter = classType.getHaxeClass().findArrayAccessGetter(resolver);
if (arrayAccessGetter instanceof HaxeMethodDeclaration methodDeclaration) {
if (classType.getHaxeClass() != null) { // need to check if Haxe class exists as it will be null when SDK is missing
HaxeNamedComponent arrayAccessSetter = classType.getHaxeClass().findArrayAccessSetter(resolver);
if (arrayAccessSetter instanceof HaxeMethodDeclaration methodDeclaration) {
HaxeMethodModel methodModel = methodDeclaration.getModel();
// make sure we are using class level typeParameters (and not method level)
if (methodModel.getGenericParams().isEmpty()) {
List<HaxeParameterModel> parameters = methodModel.getParameters();
HaxeParameterModel keyParameter = parameters.get(0);
HaxeTypeTag keyParamPsi = keyParameter.getTypeTagPsi();

HaxeTypeTag keyParamPsi = parameters.get(0).getTypeTagPsi();
HaxeTypeTag valueParamPsi = parameters.get(1).getTypeTagPsi();


@NotNull String[] specificNames = classResolver.names();
for (int i = 0; i < specificNames.length; i++) {
String keyPsiName = keyParamPsi.getTypeOrAnonymous().getType().getText();
// key
if (keyPsiName.equals(specificNames[i])) {
HaxeExpression keyExpression = arrayAccessExpression.getExpressionList().get(1);
ResultHolder handle = handle(keyExpression, context, resolver);
ResultHolder handle = handle(keyExpression, context, resolver);
if (type.getSpecifics()[i].isUnknown()) {
type.getSpecifics()[i] = handle;
}else {
}
else {
ResultHolder unified = HaxeTypeUnifier.unify(handle, type.getSpecifics()[i]);
type.getSpecifics()[i] = unified;
}
}
// value
if (arrayAccessExpression.getParent() instanceof HaxeBinaryExpression binaryExpression) {
String valuePsiName = valueParamPsi.getTypeOrAnonymous().getType().getText();
if (valuePsiName.equals(specificNames[i])) {
HaxeExpression keyExpression = binaryExpression.getExpressionList().get(1);
ResultHolder handle = handle(keyExpression, context, resolver);
if (type.getSpecifics()[i].isUnknown()) {
type.getSpecifics()[i] = handle;
}
else {
ResultHolder unified = HaxeTypeUnifier.unify(handle, type.getSpecifics()[i]);
type.getSpecifics()[i] = unified;
}
}
}
}
}
}
else {
HaxeNamedComponent arrayAccessGetter = classType.getHaxeClass().findArrayAccessGetter(resolver);
if (arrayAccessGetter instanceof HaxeMethodDeclaration methodDeclaration) {
HaxeMethodModel methodModel = methodDeclaration.getModel();
// make sure we are using class level typeParameters (and not method level)
if (methodModel.getGenericParams().isEmpty()) {
List<HaxeParameterModel> parameters = methodModel.getParameters();
HaxeParameterModel keyParameter = parameters.get(0);
HaxeTypeTag keyParamPsi = keyParameter.getTypeTagPsi();

@NotNull String[] specificNames = classResolver.names();
for (int i = 0; i < specificNames.length; i++) {
String keyPsiName = keyParamPsi.getTypeOrAnonymous().getType().getText();
if (keyPsiName.equals(specificNames[i])) {
HaxeExpression keyExpression = arrayAccessExpression.getExpressionList().get(1);
ResultHolder handle = handle(keyExpression, context, resolver);
if (type.getSpecifics()[i].isUnknown()) {
type.getSpecifics()[i] = handle;
}
else {
ResultHolder unified = HaxeTypeUnifier.unify(handle, type.getSpecifics()[i]);
type.getSpecifics()[i] = unified;
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static public boolean canAssignToFrom(
@Nullable PsiElement fromOrigin
) {
if (to == null || from == null) return false;
if (to.isDynamic() || from.isDynamic()) return true;


from = replaceMacroExprIfFromMacroMethod(from, fromOrigin);

Expand All @@ -157,6 +157,8 @@ static public boolean canAssignToFrom(
from = classReference.fullyResolveTypeDefAndUnwrapNullTypeReference();
}
}
if (to.isAny()) return true;
if (to.isDynamic() || from.isDynamic()) return true;

// if abstract of function is being compared to a function we map the abstract to its underlying function
if (isFunctionTypeOrReference(from) && to.isAbstractType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ else if (reference.isNullType()) {
if (unwrapped instanceof SpecificHaxeClassReference haxeClassReference) {
haxeClass = haxeClassReference.getHaxeClass();
resolver = haxeClassReference.getGenericResolver();
reference = haxeClassReference;
}
else if (unwrapped instanceof SpecificFunctionReference functionReference) {
return resolver.resolve(functionReference);
Expand Down

0 comments on commit 8a35ede

Please sign in to comment.