From 564977a7839eae9b8553661981ee25d31917fc0c Mon Sep 17 00:00:00 2001
From: m0rkeulv <github@m0rkeulv.net>
Date: Sun, 4 Feb 2024 13:43:27 +0100
Subject: [PATCH] Avoid assign check when init expression is invalid.

---
 .../ide/annotator/semantics/HaxeSemanticsUtil.java    |  1 +
 .../plugins/haxe/model/type/HaxeTypeCompatible.java   | 11 +++++++++--
 .../plugins/haxe/model/type/ResultHolder.java         |  4 ++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeSemanticsUtil.java b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeSemanticsUtil.java
index 50f0a063d..9e47b4f67 100644
--- a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeSemanticsUtil.java
+++ b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeSemanticsUtil.java
@@ -31,6 +31,7 @@ public static void check(
     ) {
       final ResultHolder varType = HaxeTypeResolver.getTypeFromTypeTag(tag, erroredElement);
       final ResultHolder initType = getTypeFromVarInit(initExpression, varType);
+      if (initType.isInvalid()) return;
 
       if (!varType.canAssign(initType)) {
 
diff --git a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeTypeCompatible.java b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeTypeCompatible.java
index 29431f69c..c8b1c8068 100644
--- a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeTypeCompatible.java
+++ b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeTypeCompatible.java
@@ -481,8 +481,15 @@ private static boolean containsAllMembers(SpecificHaxeClassReference to, Specifi
 
     if (to == null || from == null) return false;
 
-    List<HaxeMemberModel> toMembers = to.getHaxeClassModel().getAllMembers(to.getGenericResolver());
-    List<HaxeMemberModel> fromMembers = from.getHaxeClassModel().getAllMembers(to.getGenericResolver());
+    HaxeClassModel toClassModel = to.getHaxeClassModel();
+    HaxeClassModel fromClassModel = from.getHaxeClassModel();
+
+    // unable to determine, consider if we should return true or false in this case
+    if (toClassModel == null ||  fromClassModel == null)
+       return false;
+
+    List<HaxeMemberModel> toMembers = toClassModel.getAllMembers(to.getGenericResolver());
+    List<HaxeMemberModel> fromMembers = fromClassModel.getAllMembers(to.getGenericResolver());
     for (HaxeMemberModel member : toMembers) {
       String name = member.getName();
       // TODO  type check parameter and return type
diff --git a/src/main/java/com/intellij/plugins/haxe/model/type/ResultHolder.java b/src/main/java/com/intellij/plugins/haxe/model/type/ResultHolder.java
index 60def2015..8f9b3432d 100644
--- a/src/main/java/com/intellij/plugins/haxe/model/type/ResultHolder.java
+++ b/src/main/java/com/intellij/plugins/haxe/model/type/ResultHolder.java
@@ -179,4 +179,8 @@ public ResultHolder withOrigin(PsiElement origin) {
   public PsiElement getOrigin() {
     return origin;
   }
+
+  public boolean isInvalid() {
+    return type.isInvalid();
+  }
 }