From a5b1f25b99ff8aa0d2137f0c562680f47401cc99 Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Wed, 20 Mar 2024 19:22:12 +0100 Subject: [PATCH] bugfix: CompletionPosition inferStart should not crash --- .../meta/internal/pc/completions/Completions.scala | 3 ++- .../src/test/scala/tests/pc/CompletionSuite.scala | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/completions/Completions.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/completions/Completions.scala index a8271d106e6..a9d2ec5ca15 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/completions/Completions.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/completions/Completions.scala @@ -906,7 +906,8 @@ trait Completions { this: MetalsGlobal => } } } - loop(lastVisitedParentTrees) + val start = loop(lastVisitedParentTrees) + Math.min(start, pos.point) } /** Can character form part of an alphanumeric Scala identifier? */ diff --git a/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala index b51d0fcf4ff..37291154d7d 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionSuite.scala @@ -2281,4 +2281,15 @@ class CompletionSuite extends BaseCompletionSuite { "" ) + // THis checks if inferStart doesn't crash + check( + "infer-correct-start", + """|object O { + | val alpha = (((hex >> 24) / 0xff & 1@@).toInt + | val red = ((hex >> 16) & 0xff).toInt + |} + |""".stripMargin, + "" + ) + }