Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

compiler error for field names ending with '_' in ScalaWriter #37

Open
khoran opened this issue Dec 2, 2016 · 0 comments
Open

compiler error for field names ending with '_' in ScalaWriter #37

khoran opened this issue Dec 2, 2016 · 0 comments

Comments

@khoran
Copy link

khoran commented Dec 2, 2016

When a field name ends with _ (and likely any other symbol), the ScalaWriter class generates parameters that look like fieldName_: String. Since there is no space between the _ and the :, the scala compiler assumes the : is part of the variable name and throws a syntax error.
The fix is to just put a space before the : I imagine. Here is a guess at the relevant lines in ScalaWriter:

ScalaWriter.scala line 353:

   public ScalaWriter field(Type type, String name) throws IOException {
        line(VAR, escape(name), ": ", getGenericName(true, type));
        return compact ? this : nl();
    }
    private ScalaWriter field(String modifier, Type type, String name) throws IOException {
        line(modifier, escape(name), ": ", getGenericName(true, type));
        return compact ? this : nl();
    }
    private ScalaWriter field(String modifier, Type type, String name, String value)
            throws IOException {
        line(modifier, escape(name), ": ", getGenericName(true, type), ASSIGN, value);
        return compact ? this : nl();
    }

I was exploring the use of generated case classes when I came across this bug, that won't work for me for unrelated reasons, but I won't be able to test any fixes here. I just thought I'd point out the bug.

Kevin

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

No branches or pull requests

1 participant