# Error: access of union field 'Pointer' while field 'Optional' is active

**URL:** <https://ziggit.dev/t/error-access-of-union-field-pointer-while-field-optional-is-active/475>\
**Category:** Help\
**Created:** [November 26, 2022, 4:28pm UTC](https://ziggit.dev/t/error-access-of-union-field-pointer-while-field-optional-is-active/475 "2022-11-26T16:28:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![qrhfz](https://ziggit.dev/user_avatar/ziggit.dev/qrhfz/32/291_2.png) [@qrhfz](https://ziggit.dev/u/qrhfz)\
**Post date:** [November 26, 2022, 4:28pm UTC](https://ziggit.dev/t/error-access-of-union-field-pointer-while-field-optional-is-active/475/1 "2022-11-26T16:28:18Z")

</div>

Hello i’m new to zig.  
I’m writing a simple toy program that echo back what user input.

```zig
const std = @import("std");
// const print = std.debug.print;

pub fn main() !void {
    const allocator = std.heap.page_allocator;

    const w = std.io.getStdOut().writer();
    const r = std.io.getStdOut().reader();
    while (true) {
        try w.print("> ", .{});
        const input = try r.readUntilDelimiterOrEofAlloc(allocator, '\n', 1024);
        defer allocator.free(input);
        if (input) |s| {
            try w.print("said: {s}\n", .{s});
        }
    }
}

```

but it doesn’t compile. it says.

```zig
/home/linuxbrew/.linuxbrew/Cellar/zig/HEAD-30eb2a1/lib/zig/std/mem/Allocator.zig:488:45: error: access of union field 'Pointer' while field 'Optional' is active
    const Slice = @typeInfo(@TypeOf(memory)).Pointer;
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/zig/HEAD-30eb2a1/lib/zig/std/builtin.zig:193:18: note: union declared here
pub const Type = union(enum) {
                 ^ ~~~~
referenced by:
    main: /home/q/Dev/zig/playground/src/main.zig:12:24
    callMain: /home/linuxbrew/.linuxbrew/Cellar/zig/HEAD-30eb2a1/lib/zig/std/start.zig:614:32
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

```

line 12 is where i’m freeing the input. so if i don’t free the input the program compiles. what did i do wrong?

---

<div class="post-metadata">

**Author:** ![dude\_the\_builder](https://ziggit.dev/user_avatar/ziggit.dev/dude_the_builder/32/557_2.png) [@dude\_the\_builder](https://ziggit.dev/u/dude_the_builder)\
**Post date:** [November 26, 2022, 7:40pm UTC](https://ziggit.dev/t/error-access-of-union-field-pointer-while-field-optional-is-active/475/2 "2022-11-26T19:40:51Z")

</div>

`input` is an optional so you have to access its value via `.?` in the free call:

```zig
defer allocator.free(input.?);

```

The error message most definitely does not help.
