Skip to content

Bad indentation parsing at code misalignment #8256

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
soronpo opened this issue Feb 9, 2020 · 2 comments · Fixed by #8264
Closed

Bad indentation parsing at code misalignment #8256

soronpo opened this issue Feb 9, 2020 · 2 comments · Fixed by #8264

Comments

@soronpo
Copy link
Contributor

soronpo commented Feb 9, 2020

minimized code

Important! Keep the indentation as set in this example.

val a = 1

  trait Test[A]
  object Test {
    implicit def ev[A] : Test[A] = new Test[A]{}
  }

  val fetch = implicitly[Test[1]]

@main def main() : Unit = {}

See scastie: https://scastie.scala-lang.org/Ixn7YUAZSjSCPgKbNQR5Wg

Compilation output

no implicit argument of type Test[(1 : Int)] was found for parameter ev of method implicitly in object DottyPredef

The following import might fix the problem:

  import Test.this.Test.ev

expectation

No error.

@smarter
Copy link
Member

smarter commented Feb 9, 2020

-Xprint:parser says:

package <empty> {
  import collection.immutable._
  trait Test[A] {
    module object Test {
      implicit def ev[A]: Test[A] =
        new Test[A] {
          <empty>
        }
    }
    val fetch = implicitly[Test[1.type]]
  }
  @main() def main(): Unit =
    {
      <empty>
    }
}

Notice the object Test appears inside the trait Test, that's unexpected to say the least /cc @odersky

@odersky
Copy link
Contributor

odersky commented Feb 9, 2020

This is a nice example to illustrate why we should not just observe indentation without a specific leading token. This will be fixed once we allow only the currently specced indentation syntax, and drop supporting the old experiments.

odersky added a commit to dotty-staging/dotty that referenced this issue Feb 9, 2020
The new syntax requires a `:`. The old syntax was still supported
under a Config option which was on by default. But the test is further
confirmation that silent identation without a specific leading token
is a bad idea.
@nicolasstucki nicolasstucki linked a pull request Feb 10, 2020 that will close this issue
odersky added a commit that referenced this issue Feb 10, 2020
Fix #8256: Disallow silent indent for template bodies
gabro pushed a commit to gabro/dotty that referenced this issue Feb 11, 2020
The new syntax requires a `:`. The old syntax was still supported
under a Config option which was on by default. But the test is further
confirmation that silent identation without a specific leading token
is a bad idea.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants