Currently we have this problem with union(enum):
|
pub const Error = union(enum) { |
|
InvalidToken: InvalidToken, |
|
ExpectedVarDeclOrFn: ExpectedVarDeclOrFn, |
|
ExpectedVarDecl: ExpectedVarDecl, |
|
ExpectedAggregateKw: ExpectedAggregateKw, |
|
UnattachedDocComment: UnattachedDocComment, |
|
ExpectedEqOrSemi: ExpectedEqOrSemi, |
|
ExpectedSemiOrLBrace: ExpectedSemiOrLBrace, |
|
ExpectedColonOrRParen: ExpectedColonOrRParen, |
|
ExpectedLabelable: ExpectedLabelable, |
|
ExpectedInlinable: ExpectedInlinable, |
|
ExpectedAsmOutputReturnOrType: ExpectedAsmOutputReturnOrType, |
|
ExpectedCall: ExpectedCall, |
|
ExpectedCallOrFnProto: ExpectedCallOrFnProto, |
|
ExpectedSliceOrRBracket: ExpectedSliceOrRBracket, |
|
ExtraAlignQualifier: ExtraAlignQualifier, |
|
ExtraConstQualifier: ExtraConstQualifier, |
|
ExtraVolatileQualifier: ExtraVolatileQualifier, |
|
ExpectedPrimaryExpr: ExpectedPrimaryExpr, |
|
ExpectedToken: ExpectedToken, |
|
ExpectedCommaOrEnd: ExpectedCommaOrEnd, |
Now, if you use Error.InvalidToken are you referring to the type, or the enum value? It's ambiguous. This causes switch expressions to resort to awkward uses of @TagType:
|
switch (self.*) { |
|
// TODO https://github.com/ziglang/zig/issues/683 |
|
@TagType(Error).InvalidToken => |*x| return x.render(tokens, stream), |
|
@TagType(Error).ExpectedVarDeclOrFn => |*x| return x.render(tokens, stream), |
|
@TagType(Error).ExpectedVarDecl => |*x| return x.render(tokens, stream), |
|
@TagType(Error).ExpectedAggregateKw => |*x| return x.render(tokens, stream), |
|
@TagType(Error).UnattachedDocComment => |*x| return x.render(tokens, stream), |
|
@TagType(Error).ExpectedEqOrSemi => |*x| return x.render(tokens, stream), |
|
@TagType(Error).ExpectedSemiOrLBrace => |*x| return x.render(tokens, stream), |
However if we had a different style guide, the enum value would be Error.invalid_token and the type would be Error.InvalidToken.
This is less of a problem now that #683 is mostly solved, but there is still the ambiguity.
This sort of conflicts with #995.
Currently we have this problem with
union(enum):zig/std/zig/ast.zig
Lines 110 to 130 in aff7b38
Now, if you use
Error.InvalidTokenare you referring to the type, or the enum value? It's ambiguous. This causes switch expressions to resort to awkward uses of@TagType:zig/std/zig/ast.zig
Lines 133 to 141 in aff7b38
However if we had a different style guide, the enum value would be
Error.invalid_tokenand the type would beError.InvalidToken.This is less of a problem now that #683 is mostly solved, but there is still the ambiguity.
This sort of conflicts with #995.