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

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

@khoran

Description

@khoran

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions