Skip to content

[2.x] fix: support comma-separated imports in build.sbt#8829

Merged
eed3si9n merged 2 commits intosbt:developfrom
RenzoMXD:fix-support-comma-seperate-import
Mar 1, 2026
Merged

[2.x] fix: support comma-separated imports in build.sbt#8829
eed3si9n merged 2 commits intosbt:developfrom
RenzoMXD:fix-support-comma-seperate-import

Conversation

@RenzoMXD
Copy link
Copy Markdown
Contributor

@RenzoMXD RenzoMXD commented Feb 27, 2026

Summary

  • Fix SbtParser.importsToLineRanges to prepend import keyword when missing from Dotty's Import AST node source spans
  • Add unit test for comma-separated import parsing

Problem

import scala.util, util.Random in build.sbt fails with:

Illegal start of toplevel definition
Not found: Random

Dotty splits comma-separated imports into separate Import AST nodes, but only the first node's source span includes the import keyword. importsToLineRanges extracts raw source text, producing ("util.Random", 1) instead of ("import util.Random", 1).

Test plan

  • buildfile/src/test/scala/sbt/internal/SbtParserTest.scala` — 5 new unit tests (basic, three entries, wildcard, rename, multiple selectors)
  • sbt-app/src/sbt-test/project/comma-separated-import/build.sbt — scripted test build
  • sbt-app/src/sbt-test/project/comma-separated-import/test — scripted test script

Fixes #8826

@RenzoMXD
Copy link
Copy Markdown
Contributor Author

@eed3si9n Please review my PR. Thanks.

Copy link
Copy Markdown
Member

@xuwei-k xuwei-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add scripted test. not only SbtParserTest unit test.

@eed3si9n
Copy link
Copy Markdown
Member

@RenzoMXD Hi, thanks for the contribution! Here's a doc on scripted test - https://github.com/sbt/sbt/blob/develop/contributing-docs/05_scripted_tests.md

Please check out our Contributor's Guildeline and:

  1. Make sure you can reproduce the problem and the fix manually
  2. Include tests for the change
  3. Follow our AI assisted contributions guideline (please disclose AI usages in the PR description, if any)
  4. Multiple contributors might work on this issue in parallel
  5. Generally we recommend getting CI to pass on a forked repo before sending a pull request (pull requests that do not pass tests will be closed after a few days)
  6. Sign Scala CLA https://contribute.akka.io/contribute/cla/scala

@RenzoMXD
Copy link
Copy Markdown
Contributor Author

@eed3si9n @xuwei-k I add test cases. Please review my PR. Thanks.

@@ -0,0 +1,11 @@
import scala.util, util.Random
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eed3si9n eed3si9n merged commit 5271bab into sbt:develop Mar 1, 2026
24 of 25 checks passed
eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Mar 1, 2026
Summary
- Fix `SbtParser.importsToLineRanges` to prepend `import` keyword when missing from Dotty's `Import` AST node source spans
- Add unit test for comma-separated import parsing
eed3si9n added a commit that referenced this pull request Mar 1, 2026
Summary
- Fix `SbtParser.importsToLineRanges` to prepend `import` keyword when missing from Dotty's `Import` AST node source spans
- Add unit test for comma-separated import parsing

Co-authored-by: Renzo <[email protected]>
@RenzoMXD
Copy link
Copy Markdown
Contributor Author

RenzoMXD commented Mar 1, 2026

@eed3si9n @xuwei-k Thank you.

@RenzoMXD RenzoMXD deleted the fix-support-comma-seperate-import branch March 1, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.x] build.sbt does not support comma separated import

3 participants