Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Checking an optional interface method is implemented on an optional local variable causes a compiler assertion #2244

@TechnicalFowl

Description

@TechnicalFowl

Checking if an optional method on an interface is implemented using an optional pointer to an interface causes an assertion failure:

The compiler encountered an unexpected error: "Violated assert: ptr_type->type_kind != TYPE_FUNC_RAW".

- Function: type_get_ptr(...)
- Source file: D:\a\c3c\c3c\src\compiler\types.c:917

One file reproducer:

module repro;

import std::io;

interface VeryOptional
{
    fn void do_something() @optional;
}

struct Foo (VeryOptional)
{
    String name;
}

Foo foo = { "Foo" };

fn VeryOptional? get_very_optional()
{
    return &foo;
}

fn void main()
{
    VeryOptional? v = get_very_optional();
    if (&v.do_something)
    {
        v.do_something();
    }
    else
    {
        io::printfn("do_something is not implemented for Foo");
    }
}

Note that after fixing this I'd probably still expect to see a compiler error that I can't take reference to an optional function on a value which is itself optional. If I correctly unwrap the optional with say if (try v && &v.do_something) then everything works as expected.

Thanks!

c3c.exe --version
C3 Compiler Version:       0.7.3 (Pre-release, Jun 27 2025 01:04:54)
Installed directory:       C:/Data/c3c/build/Debug/
Git Hash:                  e986e3a8c0fcd6f9738b26a5d9308896486ce405
Backends:                  LLVM
LLVM version:              19.1.5
LLVM default target:       x86_64-pc-windows-msvc

Metadata

Metadata

Assignees

Labels

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

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions