Skip to content

Improve "Line starts with an operator" messaging to be either more vague or more precise, and less misleading #12071

@jrudolph

Description

@jrudolph

In akka-http parsing we have a lot of backquoted identifiers and there are some warnings because of that. E.g. for this code:

  // this specific ordering PREVENTS that next rule is allowed to parse `*/xyz` as a valid media range
  def `media-range-def` = rule {
    "*/*" ~ push("*") ~ push("*") |
      '*' ~ push("*") ~ push("*") |
      `type` ~ '/' ~ ('*' ~ !tchar ~ push("*") | subtype)
  }

we get this warning:

[warn] akka-http/akka-http-core/src/main/scala/akka/http/impl/model/parser/AcceptHeader.scala:41:7: Line starts with an operator that in future
[warn] will be taken as an infix expression continued from the previous line.
[warn] To force the previous interpretation as a separate statement,
[warn] add an explicit `;`, add an empty line, or remove spaces after the operator.
[warn]       `type` ~ '/' ~ ('*' ~ !tchar ~ push("*") | subtype)
[warn]       ^

In this case, we can use type only backquoted because it's a keyword otherwise.

[warn] akka-http/akka-http-core/src/main/scala/akka/http/impl/model/parser/SimpleHeaders.scala:110:7: Line starts with an operator that in future
[warn] will be taken as an infix expression continued from the previous line.
[warn] To force the previous interpretation as a separate statement,
[warn] add an explicit `;`, add an empty line, or remove spaces after the operator.
[warn]       `Cookie` {
[warn]       ^

Here, we use the backquotes for consistency because other header classes contain dashes and need the backquotes.

I don't quite understand if the warning is correct or if this code will indeed stop to parse in the future.

In those above cases, the identifiers are in operand-position of an infix expression. Would it be ambiguous in a future version how that should be parsed or would the compiler still figure out that we have a chain of infix operations that have a fixed pattern of operand operator operand operator operand ...? If that's the case, the warning should be suppressed if a backquoted identifier is found in operand position.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions