From 2f68fcdcce81311ae6c6d450939c58210c986685 Mon Sep 17 00:00:00 2001
From: Eric Milles <eric.milles@thomsonreuters.com>
Date: Wed, 19 Jan 2022 14:47:15 -0600
Subject: [PATCH] Fix for #1337: void type for statements

---
 .../search/TypeInferencingVisitorWithRequestor.java  |  5 ++---
 .../eclipse/test/ui/SemanticHighlightingTests.groovy | 12 +++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/TypeInferencingVisitorWithRequestor.java b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/TypeInferencingVisitorWithRequestor.java
index e45ceb499f..28487cf4f0 100644
--- a/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/TypeInferencingVisitorWithRequestor.java
+++ b/base/org.eclipse.jdt.groovy.core/src/org/eclipse/jdt/groovy/search/TypeInferencingVisitorWithRequestor.java
@@ -1956,9 +1956,8 @@ private boolean handleStatement(final Statement node) {
             }
         }
 
-        // don't check the lookups because statements have no type;
-        // but individual requestors may choose to end the visit here
-        TypeLookupResult noLookup = new TypeLookupResult(declaring, declaring, declaring, TypeConfidence.EXACT, scope);
+        // do not check the lookups because statements have no type; however individual requestors may choose to end the visit here
+        TypeLookupResult noLookup = new TypeLookupResult(VariableScope.VOID_CLASS_NODE, declaring, null, TypeConfidence.EXACT, scope);
         VisitStatus status = notifyRequestor(node, requestor, noLookup);
         switch (status) {
         case CONTINUE:
diff --git a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy
index 30318bf6c3..3fe5962474 100644
--- a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy
+++ b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/ui/SemanticHighlightingTests.groovy
@@ -2673,14 +2673,14 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite {
         String contents = '''
             |class C {
             |  @Deprecated def x
-            |  def y() { x }
+            |  def m() { x }
             |}
             |'''.stripMargin()
 
         assertHighlighting(contents,
             new HighlightedTypedPosition(contents.indexOf('C'), 1, CLASS),
             new HighlightedTypedPosition(contents.indexOf('x'), 1, DEPRECATED),
-            new HighlightedTypedPosition(contents.lastIndexOf('y'), 1, METHOD),
+            new HighlightedTypedPosition(contents.indexOf('m'), 1, METHOD),
             new HighlightedTypedPosition(contents.lastIndexOf('x'), 1, DEPRECATED))
     }
 
@@ -2690,13 +2690,15 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite {
             |@Deprecated
             |class C {
             |  C x
+            |  def m() { null }
             |}
             |'''.stripMargin()
 
         assertHighlighting(contents,
-            new HighlightedTypedPosition(contents.indexOf('C'), 1, DEPRECATED),
-            new HighlightedTypedPosition(contents.lastIndexOf('C'), 1, DEPRECATED),
-            new HighlightedTypedPosition(contents.lastIndexOf('x'), 1, FIELD))
+            new HighlightedTypedPosition(contents.indexOf('C {'), 1, DEPRECATED),
+            new HighlightedTypedPosition(contents.indexOf('C x'), 1, DEPRECATED),
+            new HighlightedTypedPosition(contents.indexOf('x'), 1, FIELD),
+            new HighlightedTypedPosition(contents.indexOf('m'), 1, METHOD))
     }
 
     @Test