Skip to content

non-informative error message for a transparent soft keyword with multiple new lines after it #11712

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

Closed
unkarjedy opened this issue Mar 12, 2021 · 7 comments · Fixed by #14959
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement
Milestone

Comments

@unkarjedy
Copy link
Contributor

Compiler version

3.0.0-RC1

Minimized code

def transparent = println("transparent method called")

transparent
println()
inline def f1 = 1

transparent
inline def f2 = 2

transparent
trait T1

transparent

inline def f3 = 3

transparent

def f4 = 4

transparent

trait T2

Output

Ther actually IS "start of definition" though the error says that there is no

image

Expectation

More informative message? (maybe better parsing? not sure)

@odersky odersky added area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement and removed itype:bug area:parser labels Mar 14, 2021
@odersky
Copy link
Contributor

odersky commented Apr 8, 2022

If there are multiple newlines after transparent it's an identifier, not a soft keyword.

@odersky odersky closed this as completed Apr 8, 2022
@unkarjedy
Copy link
Contributor Author

@odersky
from https://dotty.epfl.ch/docs/reference/soft-modifier.html

A soft modifier is treated as potential modifier of a definition if it is followed by a hard modifier or a keyword combination starting a definition (def, val, var, type, given, class, trait, object, enum, case class, case object). Between the two words there may be a sequence of newline tokens and soft modifiers.

Which contradicts to:

If there are multiple newlines after transparent it's an identifier, not a soft keyword.

Also, if so, why the compiler then says "expected start of definition" and doesn't treat transparent as a function call at those places?

object A {
  def transparent: Int = {
    println("transparent method called")
    42
  }

  transparent
  println()

  transparent
  inline def f1 = 2

  transparent

  inline def f2 = 2
  
  transparent

  def f3 = 2
}

image

It seems that implementation should be patched in any case.
And specification should probably also be reviewed.

@som-snytt
Copy link
Contributor

Thanks, unkarjedy.

I had to re-read the spec (both of them). All the [nl] vs {nl} vs nl not enabled is tricky. So glad it usually just works.

I see that the language about "sequence of newline tokens and soft mods" could be misconstrued as "arbitrary sequence". Probably it just means they can be "stacked".

I agree intuitively that if transparent is not taken softly as a keyword, it must be an ordinary identifier.

Here, transparent<nl><nl> is taken as a hard error, apparently.

As an aspirational footnote, it would be nice to visualize nl insertion, the way IDEs will make whitespace visible.

It's worth adding that "people don't write code like this", except when they are in the middle of an edit. Extra feedback might be helpful or annoying, depending on personal preferences.

@unkarjedy
Copy link
Contributor Author

@som-snytt

So are you implying that we should leave the compiler implementation & specification as is, without any changes?

It's worth adding that "people don't write code like this", except when they are in the middle of an edit

I agree that probability to see such code is low.
But as I see it it's now about "being in the middle of an edit"
The issue can be observed whenever someone chooses to use some soft-modifier as a declaration name, use it somewhere (e.g in some DSL, IDK...) and then decides to add some definition below the usage
(I use compiler-based highlighting in the example, so the errors come from the compiler)

image

@som-snytt
Copy link
Contributor

som-snytt commented Apr 12, 2022

I intended to agree with you, and say the "orphan" transparent should bind to your definition in scope. (That is my intuition, without looking closely yet at the mechanics.)

I also think the phrase "sequence of newlines" you pointed out in the reference should be more specific (and in the grammar). However, although I periodically re-read the rules about newlines, I never retain them; I rely just on common practices or style.

@unkarjedy
Copy link
Contributor Author

Ok, why I am asking is that I am trying to understand whether it is ok to continue keeping this ticket as "Closed" if any clarifications in the spec are going to be made

@odersky odersky reopened this Apr 16, 2022
@odersky
Copy link
Contributor

odersky commented Apr 16, 2022

@unkarjedy I think you are right, it needs a clarification or a software fix.

Maybe it's simplest to try a software fix to accept these as soft modifiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants