Closed dominikh closed 8 years ago
@dominikh would you be interested in opening a pull request for this?
Constants actually get type from their context if no type is declared. If the context doesn't define the type, they will default to whatever the default type is for the constant format, which is int
in this case.
Were you having particular errors during compilation from this or is this just clean up?
@stevvooe That's correct. Which means that code like this:
typ := p9p.QTFILE
if someCondition {
typ = p9p.QTDIR
}
fn(typ)
will fail to build. Similarly, p9p.QTDIR.String()
will work, while p9p.QTFILE.String()
will not.
Either all or none of the constants should have a type, anything else is inconsistent.
In the following piece of code
only the first constant has type QType. The other constants are untyped/will default to int when used. Constants only "inherit" the previous constant's type if no explicit value is assigned.