Giter Site home page Giter Site logo

Comments (2)

davidtorosyan avatar davidtorosyan commented on May 18, 2024 1

@bddckr I don't think #314 indicates that ktfmt used to support context receivers.

Rather, any situations in which they work right now are incidental. In that issue, they're parsed but not formatted correctly.

In your example, they're not parsed at all.


Normally I'd close this as a duplicate, but the fact that this causes a crash (instead of just bad formatting) means we should consider a mitigation at least (if a full fix is hard).

@strulovich has there been any investigation into this?

from ktfmt.

bddckr avatar bddckr commented on May 18, 2024

Adding this to TokenizerTest shows the issue:

@Test
fun `Context receivers are parsed correctly`() {
  val code = """
    |class A {
    |  context(String)
    |  fun test() {}
    |}
    |""".trimMargin().trimMargin()

  val file = Parser.parse(code)
  val tokenizer = Tokenizer(code, file)
  file.accept(tokenizer)

  assertThat(tokenizer.toks.map { it.originalText })
          .containsExactly("class", " ", "A", " ", "{", "\n", "  ", "context", "(", "String", ")", "\n", "  ", "fun", " ", "test", "(", ")", " ", "{", "}", "\n", "}")
          .inOrder()
  assertThat(tokenizer.toks.map { it.index })
          .containsExactly(0, -1, 1, -1, 2, -1, -1, 3, 4, 5, 6, -1, -1, 7, -1, 8, 9, 10, -1, 11, 12, -1, 13)
          .inOrder()
}

Changing pom.xml to use <kotlin.version>1.6.20-M1</kotlin.version> makes that test pass.

However, this is where my knowledge ends 😅 Adding this to FormatterTest shows that further changes are required to support context receivers, just like #314 explains.

@Test
fun `context receivers`() =
  assertFormatted(
      """
    |class A {
    |  context(String)
    |  fun test() {}
    |}
    |"""
          .trimMargin())

from ktfmt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.