c3lang / c3c

Compiler for the C3 language
GNU Lesser General Public License v3.0
1.34k stars 80 forks source link

Implicit cast fails for generic types #1192

Closed cbuttner closed 1 month ago

cbuttner commented 1 month ago
module foo(<SIZE>);

struct Chunk {
  char[SIZE] data;
}

struct Chunk_Array {
  Chunk* first;
  Chunk* last;
}

module bar;
import foo;

const SIZE = 16;
def My_Chunk = Chunk(<SIZE>);

fn void tester() {
  Chunk_Array(<SIZE>) array;
  My_Chunk* chunk = array.first;
  //                ^^^^^^^^^^^
  // Error: Implicitly casting 'Chunk(<16>)*' to 'My_Chunk*' (Chunk(<16>)*) is not permitted, but you may do an explicit cast by placing '(My_Chunk*)' before the expression.
}

This seems to occur when at least one of the generic parameters is a constant.

lerno commented 1 month ago

This should now work in master and dev

cbuttner commented 1 month ago

Thanks, this fixed it on my end.