Skip to content
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

Fix recent regression with comments right before imports #1363

Conversation

alexarchambault
Copy link
Collaborator

@alexarchambault alexarchambault commented Jul 13, 2023

This fixes a recent regression when a comment precedes an import in a code block, like

@ {
    // hello
    import cats.kernel._
  }

(introduced in #1361, that fixes nice things otherwise)

Before this PR, ones gets:

Welcome to the Ammonite Repl 3.0.0-M0-33-94c5ce87 (Scala 2.13.11 Java 1.8.0_362)
@ import $ivy.`org.typelevel::cats-kernel:2.6.1`
import $ivy.$

@ {
  // hello
  import cats.kernel._
  }
import hello
import cats.kernel._

(note the import hello towards the end)

With this PR, we get the expected output at the end:

Welcome to the Ammonite Repl 3.0.0-M0-35-3a5444f1 (Scala 2.13.11 Java 1.8.0_362)
@ import $ivy.`org.typelevel::cats-kernel:2.6.1`
import $ivy.$

@ {
  // hello
  import cats.kernel._
  }
import cats.kernel._

@alexarchambault alexarchambault merged commit e445eb4 into com-lihaoyi:main Jul 13, 2023
@alexarchambault alexarchambault deleted the fix-comment-and-import-regression branch July 13, 2023 13:58
lihaoyi added a commit to com-lihaoyi/mill that referenced this pull request Aug 8, 2023
… or whitespace (#2686)

This is basically a port of the following fix in the Ammonite repo
com-lihaoyi/Ammonite#1361. There were some
changes when the logic was first ported from Ammonite to Mill, resulting
in a much smaller code change than was necessary in the Ammonite repo

There are two related follow up PRs that AFAICT do not apply to Mill:
com-lihaoyi/Ammonite#1363
and com-lihaoyi/Ammonite#1369. Both have to do
with the special handling of multi-statement top-level-blocks `{...}`,
that is a thing in the Ammonite REPL (to allow multiple top-level
declarations to be entered into the REPL before submitting it) but
doesn't apply to Mill scripts.

I have updated the integration tests to include a bunch of random
comments and imports to reproduce the problem causing the tests to fail,
and verified the fix causes the tests to pass. Also this caused a
previously passing test to fail (`2-custom-build-logic`), which on
inspection appears like it was asserting the wrong thing, so I fixed the
assert

Fixes #2681
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants