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

Error formatting type #1720

Closed
ekrich opened this issue Feb 17, 2020 · 3 comments · Fixed by #1731
Closed

Error formatting type #1720

ekrich opened this issue Feb 17, 2020 · 3 comments · Fixed by #1731
Labels

Comments

@ekrich
Copy link

ekrich commented Feb 17, 2020

This template is a guideline, not a strict requirement.

  • Version: 2.4.1 (2.3.2 did not cause the error)
  • Integration: Command Line
  • Configuration:
version = 2.4.1
style = defaultWithAlign
docstrings = JavaDoc
assumeStandardLibraryStripMargin = true
project.excludeFilters = [
  scalalib/
]
project.git = true
# changed 1.6 or after
align.openParenCallSite = true
align.openParenDefnSite = true
# avoid wrapping parens on new line
danglingParentheses.defnSite = false
danglingParentheses.callSite = false
# leave literals alone
literals.long = unchanged
literals.float = unchanged
literals.double = unchanged

Steps

When running $ scripts/scalafmt unit-tests/src/test/scala/scala/scalanative/unsafe/TagSuite.scala
Given code like this:

 type iovec = CStruct2[Ptr[Byte], // iov_base
                        CSize] // iov_len

Problem

Scalafmt errors

org.scalafmt.cli.FailedToFormat: /Users/eric/workspace/scala-native/unit-tests/src/test/scala/scala/scalanative/unsafe/TagSuite.scala
Caused by: org.scalafmt.Error$PreciseIncomplete: /Users/eric/workspace/scala-native/unit-tests/src/test/scala/scala/scalanative/unsafe/TagSuite.scala:144: error: Unable to format file due to bug in scalafmt
  type iovec = CStruct2[Ptr[Byte], // iov_base
                                   ^
	at org.scalafmt.Scalafmt$.formatCode(Scalafmt.scala:86)
	at org.scalafmt.cli.ScalafmtCoreRunner$.unsafeHandleFile(ScalafmtCoreRunner.scala:87)
	at org.scalafmt.cli.ScalafmtCoreRunner$.handleFile(ScalafmtCoreRunner.scala:66)
	at org.scalafmt.cli.ScalafmtCoreRunner$.$anonfun$run$3(ScalafmtCoreRunner.scala:44)
	at org.scalafmt.cli.ScalafmtCoreRunner$.$anonfun$run$3$adapted(ScalafmtCoreRunner.scala:43)
	at scala.collection.Iterator.foreach(Iterator.scala:941)
	at scala.collection.Iterator.foreach$(Iterator.scala:941)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1429)
	at scala.collection.parallel.ParIterableLike$Foreach.leaf(ParIterableLike.scala:974)
	at scala.collection.parallel.Task.$anonfun$tryLeaf$1(Tasks.scala:53)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at scala.util.control.Breaks$$anon$1.catchBreak(Breaks.scala:67)
	at scala.collection.parallel.Task.tryLeaf(Tasks.scala:56)
	at scala.collection.parallel.Task.tryLeaf$(Tasks.scala:50)
	at scala.collection.parallel.ParIterableLike$Foreach.tryLeaf(ParIterableLike.scala:971)
	at scala.collection.parallel.AdaptiveWorkStealingTasks$WrappedTask.compute(Tasks.scala:153)
	at scala.collection.parallel.AdaptiveWorkStealingTasks$WrappedTask.compute$(Tasks.scala:149)
	at scala.collection.parallel.AdaptiveWorkStealingForkJoinTasks$WrappedTask.compute(Tasks.scala:440)
	at java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:189)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Scalafmt formats code like this:

No code change

Expectation

No errors.

I would like the formatted output to look like this:

type iovec = CStruct2[Ptr[Byte], // iov_base
                      CSize]     // iov_len

Workaround

I've found that by writing the code like this the error goes away but no formatting occurs.

type iovec = CStruct2[Ptr[Byte], // iov_base
                      CSize     // iov_len
]
Edit: this is not really a workaround but may hint at the problem.
@ekrich
Copy link
Author

ekrich commented Feb 17, 2020

Could be somewhat related to this feature.
#1249

@poslegm
Copy link
Collaborator

poslegm commented Feb 22, 2020

Minimal config for reproduce:

version = 2.0.0-RC1

Version 1.5.1 formats code without errors:

type iovec = CStruct2[Ptr[Byte], // iov_base
                      CSize]     // iov_len

kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 22, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 22, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 22, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 22, 2020
@ekrich
Copy link
Author

ekrich commented Mar 15, 2020

Thanks for fixing this 😄

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

Successfully merging a pull request may close this issue.

2 participants