#How to make the compiler shut up

1 messages · Page 1 of 1 (latest)

shut ibex
#

the compiler is saying no field named 'x' in struct 'tracer.Triangle' at o.x

switch (obj) {
    .triangle => {

    },
    else => {
        const x = switch (obj) { inline else => |o| o.x };
        const y = switch (obj) { inline else => |o| o.y };
        const z = switch (obj) { inline else => |o| o.z };
        const lightVector = Vec3.normalize(vec3(f32,
            x - intersection.x, 
            y - intersection.y, 
            z - intersection.z
        ));
        const shade = Vec3.dot(lightVector, normalVector);
        if (shade > 0) {
            totalShade += shade;
        }
    }
}

However the flow of execution will only ever reach o.x if the obj union is not Triangle

quick ingot
#

.triangle => unreachable

obsidian radish
#
switch (obj) {
    .triangle => {

    },
    inline else => |o| {
        const lightVector = Vec3.normalize(vec3(f32,
            o.x - intersection.x, 
            o.y - intersection.y, 
            o.z - intersection.z
        ));
        const shade = Vec3.dot(lightVector, normalVector);
        if (shade > 0) {
            totalShade += shade;
        }
    }
}
quick ingot
#

to be clear, i meant .triangle => unreachable inside the const x = switch (obj, but jacob's answer is definitely better

inland fog
placid pike
inland fog
#

ow i am only looking at inline else, inline 0, 1 makes quite sense

placid pike
#

inline else generates code for each variant separately so you can treat as 1 because the variant becomes comptime known