Skip to content

Panic: stored const representation differed from its expected Monotype type #10206

Description

@JRI98
main! : List(Str) => Try({}, [Exit(I8), ..])
main! = |_| {
	match read_and_handle_message("") {
		Ok({}) => Ok({}),
		Err(_) => Err(Exit(1))
	}
}

Message : [
	INFO(Str),
]

decode_message : Str -> Try(Message, Encoding.Json.ParseErr)
decode_message = |input| {
	s = Json.parse(input)?
	Ok(INFO(s))
}

read_and_handle_message : Str -> Try({}, [StdoutErr(Str), InvalidJson(Str), MissingRequiredField(Str), ..])
read_and_handle_message = |input| {
	message = decode_message(input)?
	match message {
		INFO(_) => Ok({}),
	}
}
➜  roc git:(main) ✗ roc main.roc      

┌─────────────────────────┐
│ UNCONDITIONAL CONDITION ├─ This match value is known at compile time, so this match will always inspect the same value. ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
└┬────────────────────────┘                                                                                                                                                                                                                                                                         │
 │                                                                                                                                                                                                                                                                                                  │
 │  match read_and_handle_message("") {                                                                                                                                                                                                                                                             │
 │        ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾                                                                                                                                                                                                                                                               │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── main.roc:3:8 ┘



Found 0 error(s) and 1 warning(s) for main.roc.
thread 4849886 panic: postcheck invariant violated: stored const representation differed from its expected Monotype type
roc
  ✓ Resolving Dependencies  2ms
  ✓ Parsing                 0ms
  ✓ Name Resolution         0ms
  ✓ Type Inference          0ms
.../roc/src/postcheck/common.zig:112:24: 0x1081b9537 in invariant__anon_332039 (roc)
        std.debug.panic("postcheck invariant violated: {s}", .{message});
                       ^
.../roc/src/postcheck/monotype/lower.zig:17367:37: 0x1081b7c83 in restoreConstUseAtType (roc)
                    Common.invariant("stored const representation differed from its expected Monotype type");
                                    ^
.../roc/src/postcheck/monotype/lower.zig:17234:82: 0x1080fadff in lowerLookupExprAtType (roc)
            .top_level_const => |const_use| return try self.restoreConstUseAtType(const_use, ty, try self.evidenceForUseSite(record.expr)),
                                                                                 ^
.../roc/src/postcheck/monotype/lower.zig:18693:76: 0x10806581f in lowerExprAtType (roc)
            .lookup_local => |lookup| return try self.lowerLookupExprAtType(expr.ty, lookup.resolved, ty),
                                                                           ^
.../roc/src/postcheck/monotype/lower.zig:18351:50: 0x1080ef93b in lowerExprSpanAtTypes__anon_315652 (roc)
            lowered[i] = try self.lowerExprAtType(child, ty);
                                                 ^
.../roc/src/postcheck/monotype/lower.zig:9409:62: 0x10806998f in lowerExprWithType (roc)
                    .payloads = try self.lowerExprSpanAtTypes(tag.args, self.builder.tagPayloadTypes(ty, name)),
                                                             ^
.../roc/src/postcheck/monotype/lower.zig:18733:51: 0x10806731b in lowerExprAtType (roc)
        const lowered = try self.lowerExprWithType(checked_expr, ty);
                                                  ^
.../roc/src/postcheck/monotype/lower.zig:25290:41: 0x1080e57cb in lowerBlock__anon_315718 (roc)
                try self.lowerExprAtType(block.final_expr, ty),
                                        ^
.../roc/src/postcheck/monotype/lower.zig:9463:50: 0x10806859f in lowerExprWithType (roc)
            .block => |block| try self.lowerBlock(block, ty),
                                                 ^
.../roc/src/postcheck/monotype/lower.zig:18733:51: 0x10806731b in lowerExprAtType (roc)
        const lowered = try self.lowerExprWithType(checked_expr, ty);
                                                  ^
.../roc/src/postcheck/monotype/lower.zig:23718:40: 0x10809ef9b in lowerBranchValueAtType (roc)
        return try self.lowerExprAtType(body, result_ty);
                                       ^
.../roc/src/postcheck/monotype/lower.zig:25083:75: 0x1080e9f07 in lowerIfBranchBody (roc)
        if (merge_binders.len == 0) return try self.lowerBranchValueAtType(body, result_ty);
                                                                          ^
.../roc/src/postcheck/monotype/lower.zig:25071:47: 0x1080e8993 in lowerIf__anon_320721 (roc)
                try else_ctx.lowerIfBranchBody(if_.final_else, result_ty, branch_ty, merge_binders),
                                              ^
.../roc/src/postcheck/monotype/lower.zig:24966:41: 0x1080e5b43 in lowerIfExpr__anon_315712 (roc)
                .data = try self.lowerIf(if_, result_ty, result_ty, &.{}, comptime_site),
                                        ^
.../roc/src/postcheck/monotype/lower.zig:9462:54: 0x10806855f in lowerExprWithType (roc)
            .if_ => |if_| return try self.lowerIfExpr(expr_id, if_, ty),
                                                     ^
.../roc/src/postcheck/monotype/lower.zig:18733:51: 0x10806731b in lowerExprAtType (roc)
        const lowered = try self.lowerExprWithType(checked_expr, ty);
                                                  ^
.../roc/src/postcheck/monotype/lower.zig:23718:40: 0x10809ef9b in lowerBranchValueAtType (roc)
        return try self.lowerExprAtType(body, result_ty);
                                       ^
.../roc/src/postcheck/monotype/lower.zig:23695:66: 0x10809e217 in lowerMatchBranchBody (roc)
            .value => |result_ty| try self.lowerBranchValueAtType(body, result_ty),
                                                                 ^
.../roc/src/postcheck/monotype/lower.zig:24838:56: 0x10809d953 in lowerMatch__anon_317638 (roc)
                    try branch_ctx.lowerMatchBranchBody(branch.value, output),
                                                       ^
.../roc/src/postcheck/monotype/lower.zig:23766:40: 0x10809cbc3 in lowerMatchExprWithOutput__anon_316127 (roc)
            .data = try self.lowerMatch(match, output, comptime_site),
                                       ^
.../roc/src/postcheck/monotype/lower.zig:23726:53: 0x1080e6e4b in lowerMatchExpr__anon_315708 (roc)
            return try self.lowerMatchExprWithOutput(match, .{ .value = result_ty }, comptime_site);
                                                    ^
.../roc/src/postcheck/monotype/lower.zig:9461:62: 0x108068523 in lowerExprWithType (roc)
            .match_ => |match| return try self.lowerMatchExpr(expr_id, match, ty),
                                                             ^
.../roc/src/postcheck/monotype/lower.zig:18733:51: 0x10806731b in lowerExprAtType (roc)
        const lowered = try self.lowerExprWithType(checked_expr, ty);
                                                  ^
.../roc/src/postcheck/monotype/lower.zig:25290:41: 0x1080e57cb in lowerBlock__anon_315718 (roc)
                try self.lowerExprAtType(block.final_expr, ty),
                                        ^
.../roc/src/postcheck/monotype/lower.zig:9463:50: 0x10806859f in lowerExprWithType (roc)
            .block => |block| try self.lowerBlock(block, ty),
                                                 ^
.../roc/src/postcheck/monotype/lower.zig:18733:51: 0x10806731b in lowerExprAtType (roc)
        const lowered = try self.lowerExprWithType(checked_expr, ty);
                                                  ^
.../roc/src/postcheck/monotype/lower.zig:24447:85: 0x1080c9087 in lowerBindingContinuation (roc)
                if (args.index >= args.args.len) break :blk try self.lowerExprAtType(args.body, result_ty);
                                                                                    ^
.../roc/src/postcheck/monotype/lower.zig:9056:53: 0x1081f8733 in lowerLambdaArgsAndBody (roc)
        var body = try self.lowerBindingContinuation(.{ .materialized_args = .{
                                                    ^
.../roc/src/postcheck/monotype/lower.zig:8996:56: 0x1081f8167 in lowerLambdaTemplate__anon_306865 (roc)
        const lowered = try self.lowerLambdaArgsAndBody(lambda.args, arg_tys, lambda.body, fn_data.ret);
                                                       ^
.../roc/src/postcheck/monotype/lower.zig:8883:69: 0x107fc61e3 in lowerTemplateBody (roc)
                    .lambda => |lambda| try self.lowerLambdaTemplate(lambda, fn_ty),
                                                                    ^
.../roc/src/postcheck/monotype/lower.zig:1588:55: 0x107faa7bf in lowerTemplateWithMonoFor (roc)
        const lowered = try body_ctx.lowerTemplateBody(template_ref, template, body_fn_ty);
                                                      ^
.../roc/src/postcheck/monotype/lower.zig:3245:50: 0x107fa8337 in drainSpecRequestsFrom (roc)
            _ = try self.lowerTemplateWithMonoFor(
                                                 ^
.../roc/src/postcheck/monotype/lower.zig:3223:39: 0x107fa7fd7 in drainSpecRequests (roc)
        try self.drainSpecRequestsFrom(graph, 0);
                                      ^
.../roc/src/postcheck/monotype/lower.zig:1590:35: 0x107faa893 in lowerTemplateWithMonoFor (roc)
        try self.drainSpecRequests(graph);
                                  ^
.../roc/src/postcheck/monotype/lower.zig:3245:50: 0x107fa8337 in drainSpecRequestsFrom (roc)
            _ = try self.lowerTemplateWithMonoFor(
                                                 ^
.../roc/src/postcheck/monotype/lower.zig:3223:39: 0x107fa7fd7 in drainSpecRequests (roc)
        try self.drainSpecRequestsFrom(graph, 0);
                                      ^
.../roc/src/postcheck/monotype/lower.zig:1590:35: 0x107faa893 in lowerTemplateWithMonoFor (roc)
        try self.drainSpecRequests(graph);
                                  ^
.../roc/src/postcheck/monotype/lower.zig:3245:50: 0x107fa8337 in drainSpecRequestsFrom (roc)
            _ = try self.lowerTemplateWithMonoFor(
                                                 ^
.../roc/src/postcheck/monotype/lower.zig:3223:39: 0x107fa7fd7 in drainSpecRequests (roc)
        try self.drainSpecRequestsFrom(graph, 0);
                                      ^
.../roc/src/postcheck/monotype/lower.zig:1590:35: 0x107faa893 in lowerTemplateWithMonoFor (roc)
        try self.drainSpecRequests(graph);
                                  ^
.../roc/src/postcheck/monotype/lower.zig:3245:50: 0x107fa8337 in drainSpecRequestsFrom (roc)
            _ = try self.lowerTemplateWithMonoFor(
                                                 ^
.../roc/src/postcheck/monotype/lower.zig:3223:39: 0x107fa7fd7 in drainSpecRequests (roc)
        try self.drainSpecRequestsFrom(graph, 0);
                                      ^
.../roc/src/postcheck/monotype/lower.zig:1590:35: 0x107faa893 in lowerTemplateWithMonoFor (roc)
        try self.drainSpecRequests(graph);
                                  ^
.../roc/src/postcheck/monotype/lower.zig:1327:49: 0x1081b6de7 in lowerTemplateWithMono (roc)
        return try self.lowerTemplateWithMonoFor(template_ref, method_scope, source_fn_ty, source_fn_key, fn_ty, evidence, null, null, null, null, null);
                                                ^
.../roc/src/postcheck/monotype/lower.zig:1315:46: 0x10827028b in lowerTemplate (roc)
        return try self.lowerTemplateWithMono(template_ref, source_ty_view, source_fn_ty, source_ty_view.types.rootKey(source_fn_ty), fn_ty, &.{});
                                             ^
.../roc/src/postcheck/monotype/lower.zig:993:47: 0x10826962f in lowerRoot (roc)
            const def = try self.lowerTemplate(template, moduleView(self.root_view), request.checked_type);
                                              ^
.../roc/src/postcheck/monotype/lower.zig:114:30: 0x107f0fa17 in run (roc)
        try builder.lowerRoot(request);
                             ^
.../roc/src/lir/checked_pipeline.zig:218:48: 0x107a819c7 in lowerCheckedModulesToLir (roc)
    var mono = try postcheck.Monotype.Lower.run(
                                               ^
.../roc/src/cli/main.zig:9751:56: 0x109646157 in lowerCheckedSourceToLir (roc)
    return lir.CheckedPipeline.lowerCheckedModulesToLir(
                                                       ^
.../roc/src/cli/main.zig:5614:46: 0x10a604c73 in lowerLirWithBuildEnv (roc)
    var lowered = try lowerCheckedSourceToLir(
                                             ^
.../roc/src/cli/main.zig:5686:50: 0x10a602ed7 in buildLirImageWithBuildEnv (roc)
    var lowered_result = try lowerLirWithBuildEnv(
                                                 ^
.../roc/src/cli/main.zig:3024:53: 0x10a628157 in rocRunDefaultApp (roc)
    const shm_result = try buildLirImageWithBuildEnv(
                                                    ^
.../roc/src/cli/main.zig:2250:32: 0x10a5cef7b in rocRunSharedMemoryShim (roc)
        return rocRunDefaultApp(ctx, args, source);
                               ^
.../roc/src/cli/main.zig:2232:53: 0x10a5cd6df in rocRun (roc)
        .interpreter, .dev => rocRunSharedMemoryShim(ctx, args, arg0),
                                                    ^
.../roc/src/cli/main.zig:1187:19: 0x107358197 in mainArgs (roc)
            rocRun(&ctx, run_args, args[0]) catch |err| switch (err) {
                  ^
.../roc/src/cli/main.zig:1052:13: 0x1073569e7 in main (roc)
    mainArgs(gpa, arena, args, init.io) catch |err| {
            ^
/opt/homebrew/Cellar/zig/0.16.0_1/lib/zig/std/start.zig:737:30: 0x10735308b in callMain (roc)
    return wrapMain(root.main(.{
                             ^
???:?:?: 0x183903dff in start (/usr/lib/dyld)
[1]    1806 abort      roc main.roc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions