Skip to content

fix: StringIndexOutOfBoundsException in presentation compiler's hasColon method #23498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@ object OverrideCompletions:
Context
): Option[Int] =
defn match
case td: TypeDef if text.charAt(td.rhs.span.end) == ':' =>
case td: TypeDef if (td.rhs.span.end < text.length) && text.charAt(td.rhs.span.end) == ':' =>
Some(td.rhs.span.end)
case TypeDef(_, temp : Template) =>
temp.parentsOrDerived.lastOption.map(_.span.end).filter(text.charAt(_) == ':')
temp.parentsOrDerived.lastOption.map(_.span.end).filter(idx => text.length > idx && text.charAt(idx) == ':')
case _ => None

private def fallbackFromParent(parent: Tree, name: String)(using Context) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,59 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite:
|""".stripMargin
)

@Test def `empty-lines-between-members` =
@Test def `no-new-line` =
checkEdit(
"""|package a
|
|object A {
| trait Base {
| def foo(x: Int): Int
| def bar(x: String): String
| }
| class <<Concrete>> extends Base {
|
| def bar(x: String): String = ???
|
| }
|}
|""".stripMargin,
|
|trait X:
| def foo: Unit
|
|class <<Y>> extends X""".stripMargin,
"""|package a
|
|object A {
| trait Base {
| def foo(x: Int): Int
| def bar(x: String): String
| }
| class Concrete extends Base {
|
|trait X:
| def foo: Unit
|
| override def foo(x: Int): Int = ???
|class Y extends X {
|
| def bar(x: String): String = ???
| override def foo: Unit = ???
|
| }
|}
|""".stripMargin
|}""".stripMargin,
)

@Test def `empty-lines-between-members` =
checkEdit(
"""|package a
|
|object A {
| trait Base {
| def foo(x: Int): Int
| def bar(x: String): String
| }
| class <<Concrete>> extends Base {
|
| def bar(x: String): String = ???
|
| }
|}
|""".stripMargin,
"""|package a
|
|object A {
| trait Base {
| def foo(x: Int): Int
| def bar(x: String): String
| }
| class Concrete extends Base {
|
|
| override def foo(x: Int): Int = ???
|
| def bar(x: String): String = ???
|
| }
|}
|""".stripMargin
)

@Test def `objectdef` =
Expand Down
Loading