Skip to content

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

Open
@unkarjedy

Description

@unkarjedy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions