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

Parser counts one new line instead of two #5740

Closed
scabug opened this issue May 3, 2012 · 6 comments
Closed

Parser counts one new line instead of two #5740

scabug opened this issue May 3, 2012 · 6 comments

Comments

@scabug
Copy link

scabug commented May 3, 2012

class P {
  1 to
  //comment
  5
}

This code shouldn't compile, because there are two new line chars between "1 to" and "5" and such code looks weird to be compilable (other thing is about block comments, which explicitly contains new line chars).

@scabug
Copy link
Author

scabug commented May 3, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5740?orig=1
Reporter: @Alefas
Affected Versions: 2.9.2

@scabug
Copy link
Author

scabug commented May 3, 2012

@paulp said:
There's only one newline character which isn't part of a comment. It doesn't seem like a bug to me.

@scabug
Copy link
Author

scabug commented May 3, 2012

@Alefas said:
I think line comment shouldn't contain newline character. However anyway it seems it strictly depends on implementation. As for me it's ok to get any of two resolutions (a bug or not a bug).

@scabug
Copy link
Author

scabug commented May 4, 2012

@Alefas said:
I just found another important case (to continue discussion):

def foo(x: Int)(y: Int) = 1

foo(1)/*
*/(2)

This is not compilable, however it seems it should be compilable.
However imagine that this code is ok, then such code also will be ok (because of newline included in comment):

foo(1)//line comment
(2)

So something about comments is wrong or not specified.

@scabug
Copy link
Author

scabug commented May 5, 2012

@paulp said (edited on May 5, 2012 8:30:35 PM UTC):
All of these compile:

  Nil map // foo
  identity

  Nil map
  // foo
  identity
  
  Nil map
  // foo
  // foo
  identity
  
  Nil map /* foo 
  */ identity
  
  Nil map /* foo */
  identity
  
  Nil map /* 
  foo 
  */
  identity
  
  Nil map /* 
  foo 
  foo
  foo
  */
  identity

But THIS does not (compare with last example.)

  Nil map /* 



  */
  identity

So you can make code uncompilable by changing the content of the comment, without even changing the number of newlines in it! It looks like a completely blank line is being counted as an nl token even if it's inside a block comment, but a line with any non-whitespace is not.

I can find pretty much nothing on how comments translate into whitespace in the spec.

@scabug
Copy link
Author

scabug commented Nov 20, 2012

@odersky said:
From the spec, as unearthed on the recent mailing list thread:

Normally, only a single \code{nl} token is inserted between two
consecutive non-newline tokens which are on different lines, even if there are multiple lines
between the two tokens. However, if two tokens are separated by at
least one completely blank line (i.e a line which contains no
printable characters), then two \code{nl} tokens are inserted.

As per suggestions on the thread, we will change this to:

Normally, only a single \code{nl} token is inserted between two
consecutive non-newline tokens which are on different lines, even if there are multiple lines
between the two tokens. However, if two tokens are separated by a character sequence containing at least one completely blank line (i.e a line which contains no printable characters), then two \code{nl} tokens are inserted. (it does not matter if the blank line appears within a comment or outside of it)

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

No branches or pull requests

2 participants