-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.docsproposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Currently we have this problem with union(enum)
:
Lines 110 to 130 in aff7b38
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
:
Lines 133 to 141 in aff7b38
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.
ikskuh, mrkishi, ifreund, artob, hamad-almamari and 7 moreemekoi, SwayUser, scheibo, kiedtl, sin-ack and 1 more
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.docsproposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.