Skip to content

for loop fails with (misaligned?) structs #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jun 23, 2018 · 0 comments
Closed

for loop fails with (misaligned?) structs #1154

ghost opened this issue Jun 23, 2018 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@ghost
Copy link

ghost commented Jun 23, 2018

const SimpleObject = struct {
  a: bool,
  b: i32,
};
// @sizeOf(SimpleObject) == 8
// @alignOf(SimpleObject) == 1 (?)

test "test" {
  const list: [20]SimpleObject = undefined;

  for (list[0..]) |*object| {
  }
}
error: expected type '*align(4) const SimpleObject', found '*const SimpleObject'
  for (list[0..]) |*object| {
  ^

Struct alignment is apparently just set to the the alignment of the first field in the struct. This code compiles if the first field is the one with the highest alignment (a single field works, i32, bool works, i16, bool works, i32, i16 works, i16, i32 fails, etc).

Directly accessing list items (e.g. &list[3]) passes, so this code will also compile if you change the for loop to a while loop.

Is this possibly related to #1052 ?

@andrewrk andrewrk added this to the 0.3.0 milestone Jun 26, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant