hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.39k stars 232 forks source link

[BUG] cppfront gives segfault on v2 class with constructor. #898

Closed tomFlowee closed 8 months ago

tomFlowee commented 8 months ago

Describe the bug

Calling cppfront Digger.cpp2 results in a segfault and an empty cpp file.

To Reproduce Steps to reproduce the behavior:

Digger.cpp2

Digger: type = {
    this: () = {
    }
}

cppfront Digger.cpp2

I'm probably doing it wrong (wanted to initialize class members there), but I think it should not crash.

gregmarr commented 8 months ago

This is the constructor syntax:

Digger: type = {
    operator=: (out this) = {
    }
}

That code looks like a base member declaration, but it has () instead of a name. It results in this error:

cppfront: source/sema.h:1240: bool cpp2::sema::check(const cpp2::declaration_node&): Assertion `n.is_object()' failed.

I guess the assert should be changed to an error.

hsutter commented 8 months ago

Thanks!