Commit 2a58e30bd5

Lachlan Easton <lachlan@lakebythewoods.xyz>
2020-09-03 12:16:12
std meta: fix use of alignOf in meta.cast
1 parent 39a80cf
Changed files (1)
lib
lib/std/meta.zig
@@ -705,34 +705,34 @@ pub fn Vector(comptime len: u32, comptime child: type) type {
 pub fn cast(comptime DestType: type, target: anytype) DestType {
     const TargetType = @TypeOf(target);
     switch (@typeInfo(DestType)) {
-        .Pointer => {
+        .Pointer => |dest_ptr| {
             switch (@typeInfo(TargetType)) {
                 .Int, .ComptimeInt => {
                     return @intToPtr(DestType, target);
                 },
                 .Pointer => |ptr| {
-                    return @ptrCast(DestType, @alignCast(ptr.alignment, target));
+                    return @ptrCast(DestType, @alignCast(dest_ptr.alignment, target));
                 },
                 .Optional => |opt| {
                     if (@typeInfo(opt.child) == .Pointer) {
-                        return @ptrCast(DestType, @alignCast(@alignOf(opt.child.Child), target));
+                        return @ptrCast(DestType, @alignCast(dest_ptr, target));
                     }
                 },
                 else => {},
             }
         },
-        .Optional => |opt| {
-            if (@typeInfo(opt.child) == .Pointer) {
+        .Optional => |dest_opt| {
+            if (@typeInfo(dest_opt.child) == .Pointer) {
                 switch (@typeInfo(TargetType)) {
                     .Int, .ComptimeInt => {
                         return @intToPtr(DestType, target);
                     },
-                    .Pointer => |ptr| {
-                        return @ptrCast(DestType, @alignCast(ptr.alignment, target));
+                    .Pointer => {
+                        return @ptrCast(DestType, @alignCast(@alignOf(dest_opt.child.Child), target));
                     },
                     .Optional => |target_opt| {
                         if (@typeInfo(target_opt.child) == .Pointer) {
-                            return @ptrCast(DestType, @alignCast(@alignOf(target_opt.child.Child), target));
+                            return @ptrCast(DestType, @alignCast(@alignOf(dest_opt.child.Child), target));
                         }
                     },
                     else => {},