Skip to content

spec: unclear whether # is a valid identifier #3816

@mvdan

Description

@mvdan

A hash just by itself is not a valid identifier per the spec:

https://cuelang.org/docs/reference/spec/#identifiers

identifier = [ "#" | "_#" ] letter { letter | unicode_digit } .

However, as of 2d28bd3, they clearly work in the current implementation:

exec cue export input.cue

-- input.cue --
#: "foo"
bar: #
> exec cue export input.cue
[stdout]
{
    "bar": "foo"
}

Moreover, they get used by the jsonschema encoding as well:

exec cue def input.json

-- input.json --
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$defs": {
        "some-thing": {
            "type": "string"
        }
    }
}
> exec cue def input.json
[stdout]
@jsonschema(schema="https://json-schema.org/draft/2020-12/schema")
_
#: {
	"some-thing": string
}

It may be too late or painful to remove support for hash identifiers at this point, if we never intended them to work. The easier alternative seems to be to adjust the spec to reflect reality. cc @rogpeppe

Metadata

Metadata

Assignees

No one assigned

    Labels

    spec-deviationBugs where the implementation does not follow the spec.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions