#file struct 'Io' has no member named 'File'

1 messages · Page 1 of 1 (latest)

graceful agate
#

I am trying to write a programming language in zig and I have my main.zig file
but I get an error I couldnt really understand how to fix.

nixos@nixos ~/p/src (master)> zig run main.zig -- test.txt
main.zig:31:27: error: root source file struct 'Io' has no member named 'File'
    const stdout = std.io.File.stdout().writer();
                          ^~~~
/nix/store/26p2s5il6lrbyhsclrfhhh49vcwyvfv2-zig-0.15.2/lib/zig/std/Io.zig:1:1: note: struct declared here
const builtin = @import("builtin");
^~~~~
referenced by:
    callMain [inlined]: /nix/store/26p2s5il6lrbyhsclrfhhh49vcwyvfv2-zig-0.15.2/lib/zig/std/start.zig:627:37
    callMainWithArgs [inlined]: /nix/store/26p2s5il6lrbyhsclrfhhh49vcwyvfv2-zig-0.15.2/lib/zig/std/start.zig:587:20
    posixCallMainAndExit: /nix/store/26p2s5il6lrbyhsclrfhhh49vcwyvfv2-zig-0.15.2/lib/zig/std/start.zig:542:36
    2 reference(s) hidden; use '-freference-trace=5' to see all references
#

this is my main.zig

const std = @import("std");
const token = @import("tokens.zig");
const lexer = @import("lexer.zig");
const evaluator = @import("evaluator.zig");
pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();
    const args = try std.process.argsAlloc(allocator);
    defer std.process.argsFree(allocator, args);
    if (args.len < 2) {
        std.debug.print("Usage: {s} <file>\n", .{args[0]});
        return;
    }
    const source = try std.fs.cwd().readFileAlloc(allocator, args[1], 1024 * 1024);
    defer allocator.free(source);
    var lex = lexer.Lexer.init(allocator, source);
    defer lex.deinit();
    lex.tokenize() catch |err| {
        std.debug.print("Error tokenizing: {}\n", .{err});
        return err;
    };
    const stdout = std.io.getStdOut().writer();
    var eval = evaluator.Evaluator.init(lex.tokens.items);
    eval.evaluate_all(stdout) catch |err| {
        std.debug.print("Error evaluating: {}\n", .{err});
        return err;
    };
}
sinful oyster
#

What's your zig version?

graceful agate
#
0.15.2```
sinful oyster
#

Replace the std.io.File.stdout() with std.fs.File.stdout()

#

And the writer method takes a buffer I believe

#
var buf: [512]u8 = undefined; // Example size, tweak to your hearts content
var writer = std.fs.File.stdout().writer(&buf);
const stdout = &writer.interface;
#

Don't forget to flush though!