Giter VIP home page Giter VIP logo

Comments (5)

johannescoetzee avatar johannescoetzee commented on September 27, 2024 1

Will do! I have a few other tasks keeping be busy, but I'll hopefully get to this at the end of this week or early next

from javaparser.

johannescoetzee avatar johannescoetzee commented on September 27, 2024 1

I introduced this bug in my first java 21 related PR, specifically here where I changed the Expression expected in the switch body to StatementExpression. I did that to fix semi-colon issues with the lexical preserving printer, but didn't consider the fact that not every expression is a statement expression. The tests I wrote all had either empty switch bodies, or print statements in the body, so I didn't cover the expression case. I'm working on a fix now!

from javaparser.

Kimmmey avatar Kimmmey commented on September 27, 2024

Apparently it is not only unary operators in a SwitchEntry, but also binary operators that cause parser errors.

An additional test follows:

    @Test
    void testSwitchExprWithBinaryExpr() {
        parseStatement("int i = switch (1) {\n" +
                       "    case 1 -> 1;\n" +
                       "    case 2, 3 -> 1 + 2;\n" +
                       "    default -> 1;\n" +
                       "};");
    }

Output:

[ERROR]   SwitchExprTest.testSwitchExprWithBinaryExpr:309 [(line 3,col 18) Parse error. Found "+", expected one of  "%=" "&=" "*=" "++" "+=" "--" "-=" "/=" ";" "<<=" "=" ">>=" ">>>=" "^=" "|="
Problem stacktrace : 
  com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:14249)
  com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:14094)
  com.github.javaparser.GeneratedJavaParser.StatementExpression(GeneratedJavaParser.java:6228)
  com.github.javaparser.GeneratedJavaParser.SwitchEntry(GeneratedJavaParser.java:6540)
[...]

Best regards

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

@johannescoetzee Can you take a look at this?

from javaparser.

johannescoetzee avatar johannescoetzee commented on September 27, 2024

I've opened a PR that fixes this issue.

@Kimmmey thank you very much for the report and the small code examples! This was very useful for diagnosing the issue quickly :)

from javaparser.

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.