Skip to content

Compiler assert when passing untyped const to CT macro swtich-case #2689

@NotsoanoNimus

Description

@NotsoanoNimus

I was testing a completely unrelated issue and happened to catch this error in the process.


⚠️ The compiler encountered an unexpected error: "Violated assert: context->current_block".

- Function: llvm_emit_cond_br(...)
- Source file: ../src/compiler/llvm_codegen_instr.c:16

🙏 Please consider taking the time to file an issue on GitHub (https://github.com/c3lang/c3c/issues/new), so that we can get it fixed.

Repro:

module testing_branch;
import std::io;

faultdef OH_NO;
const C = 1;

fn void main() => do_thing()!!;

fn void? do_thing()
{
    int* a_value = mem::alloc_array(int, 4);
    // Change 'C' below to any integer value and the assert goes away.
    *(int128*)a_value = may_fault(int128, "-123", C)!;
    io::printfn("Value: %d", *a_value);
}

macro may_fault($ArgType, something, $incoming)
{
    $switch $incoming:
        $case 1: return OH_NO?;
        $default: return something.to_integer($ArgType);
    $endswitch
}

Metadata

Metadata

Assignees

Labels

BugSomething isn't workingFixed needs testingNeeds verification / testing that it now works

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions