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

Fails with receiver parameter (implicit this) #607

Closed
TamasSzigeti opened this issue Sep 19, 2023 · 0 comments · Fixed by #642
Closed

Fails with receiver parameter (implicit this) #607

TamasSzigeti opened this issue Sep 19, 2023 · 0 comments · Fixed by #642

Comments

@TamasSzigeti
Copy link

Hi, thank you for this great tool.

Although the receiver (parameter implicit this) is a rarely used syntax, but is valid in java and required when using Checker Framework, example here

Looking at the parser code I see that it is supported in constructors

Input:

class Foo {
    public void test(Foo this) {
        // This fails
    }

    public void test(Foo this, Bar that) {
        // This fails
    }
}

Output:

[error] Foo.java: Error: Sad sad panda, parsing errors detected in line: 2, column: 26!
[error] Expecting --> '...' <-- but found --> 'this' <--!
[error]         ->compilationUnit
[error]         ->ordinaryCompilationUnit
[error]         ->typeDeclaration
[error]         ->classDeclaration
[error]         ->normalClassDeclaration
[error]         ->classBody
[error]         ->classBodyDeclaration
[error]         ->classMemberDeclaration
[error]         ->methodDeclaration
[error]         ->methodHeader
[error]         ->methodDeclarator
[error]         ->formalParameterList
[error]         ->formalParameter
[error]         ->variableArityParameter
[error]     at Object.parse (<…>/prettier-java-repro/node_modules/java-parser/src/index.js:41:11)
[error]     at Object.parse (<…>/prettier-java-repro/node_modules/prettier-plugin-java/dist/parser.js:4:23)
[error]     at parse (file://<…>/prettier-java-repro/node_modules/prettier/index.mjs:16786:24)
[error]     at async coreFormat (file://<…>/prettier-java-repro/node_modules/prettier/index.mjs:18107:7)
[error]     at async formatWithCursor (file://<…>/prettier-java-repro/node_modules/prettier/index.mjs:18309:14)
[error]     at async formatFiles (file://<…>/prettier-java-repro/node_modules/prettier/internal/cli.mjs:7082:18)
[error]     at async main (file://<…>/prettier-java-repro/node_modules/prettier/internal/cli.mjs:7274:5)
[error]     at async Module.run (file://<…>/prettier-java-repro/node_modules/prettier/internal/cli.mjs:7228:5)
error Command failed with exit code 2.

Weirdly I found some mentions of receiver parameter but in the constructorDeclarator where it shouldn't be supported

Thanking in advance

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