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

Use correct range for error in escape [ci: last-only] #10740

Closed
wants to merge 5 commits into from

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Apr 7, 2024

Fixes scala/bug#12981

This was broken since 2.13.0 FastStringInterpolator. The bad position is just a bad caret for ordinary reporting, but causes downstream errors for other tooling.

@scala-jenkins scala-jenkins added this to the 2.13.15 milestone Apr 7, 2024
@som-snytt
Copy link
Contributor Author

som-snytt commented Apr 7, 2024

Apparently, the invariant, that point is in range, is not enforced.

I expected start <= point < end, but "zero extent" ranges are typical, also in dotty spans.

Splitting this commit into the pos fix for interpolator (plus gratuitous refactoring), then the tweak that you can request a spanning pos to include your default.point; otherwise a default.point out of range is ignored.

The tweaks improve point positioning, but as noted on the ancient PR for NamesDefault, it's difficult to code defensively because it's easy to accidentally derive a range via offsetpos.withStart. This PR is not ambitious because of likely interactions with tooling.

For example, NamePos gives the wrong position to a var x under -Yrangepos:false. Perhaps the option to turn off range positioning should be deprecated.

@som-snytt som-snytt force-pushed the issue/12981-error-pos-bloop branch 7 times, most recently from 772bb9f to ee24067 Compare April 13, 2024 22:12
@som-snytt
Copy link
Contributor Author

som-snytt commented Apr 14, 2024

At any phase.

[info] [info] welcome to sbt 1.9.9 (Oracle Corporation Java 1.8.0_332)
[info] [info] loading project definition from /tmp/sbt_612ad334/project
[info] [info] loading settings for project sbt_612ad334 from common.sbt ...
[info] [info] set current project to sbt_612ad334 (in build file:/tmp/sbt_612ad334/)
[info] [info] compiling 2 Scala sources to /tmp/sbt_612ad334/target/classes ...
[info] [error] ## Exception when compiling 2 sources to /tmp/sbt_612ad334/target/classes
[info] [error] java.lang.NoClassDefFoundError: scala/collection/Seq$
[info] [error] scala.reflect.internal.Definitions$DefinitionsClass.Collection_SeqModule$lzycompute(Definitions.scala:507)
[info] [error] scala.reflect.internal.Definitions$DefinitionsClass.Collection_SeqModule(Definitions.scala:507)
[info] [error] scala.reflect.internal.Definitions$DefinitionsClass$RunDefinitions.Seq_apply$lzycompute(Definitions.scala:1735)
[info] [error] scala.reflect.internal.Definitions$DefinitionsClass$RunDefinitions.Seq_apply(Definitions.scala:1733)
[info] [error] scala.reflect.internal.Definitions$DefinitionsClass$RunDefinitions.isSeqApply(Definitions.scala:1762)
[info] [error] scala.tools.nsc.transform.CleanUp$CleanUpTransformer.transformApply(CleanUp.scala:558)
[info] [error] scala.tools.nsc.transform.CleanUp$CleanUpTransformer.transform(CleanUp.scala:726)
[info] [error] scala.tools.nsc.transform.CleanUp$CleanUpTransformer.transform(CleanUp.scala:37)

@som-snytt som-snytt force-pushed the issue/12981-error-pos-bloop branch 2 times, most recently from 6d94232 to 1688a6b Compare April 15, 2024 00:00
@som-snytt
Copy link
Contributor Author

/rebuild

@som-snytt som-snytt force-pushed the issue/12981-error-pos-bloop branch from 1688a6b to e146e7e Compare July 9, 2024 22:58
@som-snytt som-snytt changed the title Use correct range for error in escape Use correct range for error in escape [ci: last-only] Jul 10, 2024
@@ -1,4 +1,4 @@
t12155.scala:6: error: class Node in class C1 cannot be accessed as a member of C1[A,_$1] from package <empty>
class D[A, C](val x: C1[A, _]#Node[C]) {
^
^
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not an obvious improvement

@som-snytt
Copy link
Contributor Author

Maybe it's time to follow Scala 3 and underline the range instead of the finicky point.

@som-snytt
Copy link
Contributor Author

som-snytt commented Jul 10, 2024

The failure on the first commit was weird.

[info] [info] compiling 1 Scala source to /tmp/sbt_8d42cfbb/target/classes ...
[info] [error] ## Exception when compiling 1 sources to /tmp/sbt_8d42cfbb/target/classes
[info] [error] java.util.ServiceConfigurationError: xsbti.compile.CompilerInterface2: jar:file:/home/jenkins/.ivy2/local/org.scala-lang/scala2-sbt-bridge/2.13.15-bin-SNAPSHOT/jars/scala2-sbt-bridge.jar!/META-INF/services/xsbti.compile.CompilerInterface2:1: Illegal provider-class name: 6scala.tools.xsbt.CompilerBridge

The failure on the last commit was the new check file from #10792

The checks were green before rebasing.

@lrytz
Copy link
Member

lrytz commented Jul 15, 2024

Looks all good to me, thank you!

The change to WrappingPosAccumulator is a bit hard to asses. Did you maybe add some assertions to find call sites of wrappingPos / code examples where the default.point falls outside the wrapping range?

@SethTisue

This comment was marked as resolved.

@SethTisue SethTisue marked this pull request as draft July 18, 2024 17:44
@som-snytt
Copy link
Contributor Author

I intend to improve the code comment on widening pos. I believe I did start by asserting that point was in range.

@som-snytt
Copy link
Contributor Author

som-snytt commented Jul 19, 2024

I haven't looked at this again yet, but "For warnings" fails the test for positions of

val x, y = 42

where x overlaps with y, so x is focused on the x.

I didn't touch positions in that PR, but I see this touches mkClosure. Retronym's fix that induces focus was to supply the position of the rhs 42. Maybe my rhs is no longer a range, so x no longer overlaps, so x is not focused (on my other PR).

It's by a pernicious coincidence that I must refresh my memory on positions, so it might be opportune to refresh this PR.

Edit: morning after, it was just a cut/paste error.

@som-snytt som-snytt force-pushed the issue/12981-error-pos-bloop branch from 7cdc176 to ace2117 Compare July 24, 2024 01:19
@som-snytt
Copy link
Contributor Author

rebased on "for warnings".

@lrytz
Copy link
Member

lrytz commented Aug 14, 2024

let me know when it's ready for another 👀

@som-snytt
Copy link
Contributor Author

I was just looking for a new adventure in rebasing. Maybe I can figure out what to cherry-pick.

@som-snytt
Copy link
Contributor Author

Not sure about the history of the semantics of position operations, but I see these tweaks are coping with withStart always producing a range but withPoint returning either a range or moving an offset position.

Symbolic ops seem to suggest notation, x ^| y for "which point do you prefer", etc, but the promise of convenience is not realized. Scala 2 is burdened with offset positions. Imagine if in 2014 the effort was to replace positions with spans on scala 2.

@SethTisue SethTisue modified the milestones: 2.13.15, 2.13.16 Aug 14, 2024
@som-snytt som-snytt closed this Sep 11, 2024
@SethTisue SethTisue removed this from the 2.13.16 milestone Sep 11, 2024
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.

Position failure under Bloop with small source file
4 participants