Skip to content

Error message ranges related to @unroll annotation are confusing #23072

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

Open
unkarjedy opened this issue Apr 30, 2025 · 3 comments
Open

Error message ranges related to @unroll annotation are confusing #23072

unkarjedy opened this issue Apr 30, 2025 · 3 comments
Labels
area:experimental:unroll Issues tied to the @unroll annotation area:ux Issues tied to user experience. itype:bug

Comments

@unkarjedy
Copy link
Contributor

I extracted it from the #21693 comments

Compiler version

Scala 3.7.0-RC4

I played around the with the @unroll annotation and I find the error message ranges confusing

Example 0

"Cannot unroll method foo in class Example at line 5 because parameter z needs a default value"
The error is specific to a single parameter.
The whole parameter range is highlighted - OK, seems no issue.

import scala.annotation.unroll

class Example {
    final def foo(x: Int, y: Int, @unroll z: Int): Int = x + y + z
}
image

Example 1

"Cannot unroll parameters of method foo: it is not final"
The error is specific to the whole function and the @unroll annotation usage fact.
However, the range here is the parameter name identifier, which looks strange.
Nothing in the parameter z is special here, so I suppose the better range to highlight here would be just @unroll annotation

import scala.annotation.unroll

class Example {
    def foo(x: Int, y: Int, @unroll z: Int): Int = x + y + z
}
image

Example 2

"@unroll is only allowed on a method parameter"
It's shown on the name identifier foo.
To me it seems the @unroll annotation itself would be a better fit here as well - it's the annotation to blame, not the definition name identifier.

import scala.annotation.unroll

class Example {
  @unroll def foo(x: Int, y: Int, z: Int): Int = x + y + z
}
image

Note that the error at @unroll is different:

Image
@unkarjedy unkarjedy added the stat:needs triage Every issue needs to have an "area" and "itype" label label Apr 30, 2025
@unkarjedy
Copy link
Contributor Author

Also, it would be nice to clarify which experimental import should be imported.
image

Ideally, in the some structured way.
Maybe as a standard quick fix (file edit patch) or maybe some special quick fix kind (hint to an IDE which import to be added)

@unkarjedy
Copy link
Contributor Author

CC @bishabosha as the original author

@Gedochao Gedochao added area:experimental:unroll Issues tied to the @unroll annotation itype:bug area:ux Issues tied to user experience. and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 30, 2025
@Gedochao
Copy link
Contributor

Also, it would be nice to clarify which experimental import should be imported.

Actually, it seems the language import is still missing from the implementation 🤔
We should have:

import scala.language.experimental.unroll

So currently, passing -experimental is actually necessary, it seems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:unroll Issues tied to the @unroll annotation area:ux Issues tied to user experience. itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants