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

Confusing error when a fully-qualified class name is expected #83

Open
fpoli opened this issue Jun 6, 2023 · 1 comment
Open

Confusing error when a fully-qualified class name is expected #83

fpoli opened this issue Jun 6, 2023 · 1 comment

Comments

@fpoli
Copy link
Contributor

fpoli commented Jun 6, 2023

The following macro invocation seems to contain a valid Java class declaration, but duchess fails to parse it and the error message doesn't clearly explain why.

java_package!{
  package foo
  public interface Baz {}
  public interface Bazz {}
  public class Bar implements Baz, Bazz {}
}
error: unexpected token `... ss Bar implements Baz  <<< , >>>  Bazz {}` at offset 33, expected one of `["r#/"[./]/"#"]`

The reason is that the parser currently expects a fully-qualified class name after the extends, and a fully-qualified name contains at least a dot. The fixed version of the macro invocation is the following:

java_package!{
  package foo
  public interface Baz {}
  public interface Bazz {}
  public class Bar implements foo.Baz, foo.Bazz {} // <-- Note the "foo."
}

The error message above is one of the firsts that a user will encounter. Duchess should either report a more helpful error message, or the parser should accept the first code snippet. Note that a similar issue occurs when declaring the type of a field, a method parameter, or a return type. It would be great if a fix for this issue also addressed those cases.

@fpoli fpoli changed the title Confusing error when the parser expects a fully-qualified class name Confusing error when a fully-qualified class name is expected Jun 6, 2023
@nikomatsakis
Copy link
Member

That is pretty confusing, I agree. We should probably make the first one work.

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

No branches or pull requests

2 participants