Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface resolution fails when an interface is defined in one module with a parent interface and implemented in another module where the implementation has a List of that interface as a field #1348

Open
cheese3660 opened this issue Aug 11, 2024 · 1 comment
Assignees
Labels
Bug Something isn't working Fixed Needs Verification Fixed, but needs verification that it works

Comments

@cheese3660
Copy link
Contributor

cheese3660 commented Aug 11, 2024

main.c3

module minimal_repro;
import std::io;

interface IntA {

}

interface IntC : IntA {

}

fn int main(String[] args)
{
    return 0;
}

other.c3

module minimal_repro_other;
import minimal_repro;
import std::io;
import std::collections::list;

struct HasList (IntC) {
    List(<IntC>) list;
}

When compiled with c3c compile main.c3 other.c3 works perfectly fine
But when compiled with c3c compile other.c3 main.c3 does not work and instead spits out the following error

 5: 
 6: }
 7: 
 8: interface IntC : IntA {
                     ^^^^
(/home/cheese3660/c3c-stuff/minimal_repro/src/main.c3:8:18) Error: Did you mean the interface 'IntA' in module minimal_repro? If so please add 'import minimal_repro'.

 6: 
 7: def ElementPredicate = fn bool(Type *type);
 8: def ElementTest = fn bool(Type *type, any context);
 9: const ELEMENT_IS_EQUATABLE = types::is_equatable_type(Type);
                                        ^^^^^^^^^^^^^^^^^^^^^^^
(/home/cheese3660/c3c-stuff/c3c-master/lib/std/collections/list.c3:9:37) Note: Inlined from here.

As such it seems dependent on the compilation order.

And if you remove List(<IntC>) from the fields of HasList, it also compiles as expected.

@lerno lerno self-assigned this Aug 12, 2024
@lerno lerno added Bug Something isn't working In Progress This task is currently being worked on labels Aug 12, 2024
@lerno
Copy link
Collaborator

lerno commented Aug 12, 2024

I've fixed THIS error, but I feel like a more uniform approach is needed here to be honest. There is a need to consider whether interfaces should be lifted out a little bit different. Also in general it would just be nice to see if it's possible to delay initialization on some other things. Plus, it need to be SPECIFIED, not just ad hoc, what kind of circular references are needed. The hard part is:

module foo(<Type>);
struct Baz
{
    Type* x;
}
module bar;
import foo;
def BazAbc = Baz(<Abc>)
struct Abc
{
    BazAbc baz;
}

Now even though this is recursive, it actually flattens to:

struct BazAbc
{
    Abc* x;
}
struct Abc
{
   BazAbc baz;   // Basically Abc* x
}

Which is fine and a common thing you'd want.

@lerno lerno added Fixed Needs Verification Fixed, but needs verification that it works and removed In Progress This task is currently being worked on labels Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Fixed Needs Verification Fixed, but needs verification that it works
Projects
None yet
Development

No branches or pull requests

2 participants