-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix incorrect union const value generation
closes #1381 The union was generated as a 3 byte struct when it needed to be 4 bytes so that the packed struct bitcast could work correctly. Now it recognizes this situation and adds padding bytes to become the correct size so that it can fit into an array.
- Loading branch information
Showing
3 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const std = @import("std"); | ||
|
||
const B = union(enum) { | ||
D: u8, | ||
E: u16, | ||
}; | ||
|
||
const A = union(enum) { | ||
B: B, | ||
C: u8, | ||
}; | ||
|
||
test "union that needs padding bytes inside an array" { | ||
var as = []A{ | ||
A{ .B = B{ .D = 1 } }, | ||
A{ .B = B{ .D = 1 } }, | ||
}; | ||
|
||
const a = as[0].B; | ||
std.debug.assertOrPanic(a.D == 1); | ||
} |