opened
jacob-carlborg
username_0
I compile the following code with LDC 1.15.0: `ldc2 main.d foo.d`.

```d
// main.d
extern (C) extern int a;
import foo;
```

```d
// foo.d
extern (C) const int a = 3;
```

I get the following error message:

```
main.d(2): Error: Global variable type does not match previous declaration with same mangled name: a
main.d(2):        Previous IR type: i32
main.d(2):        New IR type:      i32
```

Adding `const` to `main.a` solves the problem but it's a confusing error message since the IR types are the same.
Confusing error message with unmatching types
issue
created
thewilsonator
username_1
Usually that error is generated when you have structs defined in different modules and try to use them with functions defined in the opposite module. I'm not sure why that would happen with a plain int though.
comment
created
jacob-carlborg
username_0
Because one is const the other one is not.
comment
created
thewilsonator
username_1
Obviously. what happen with structs though is their IR name includes the module name, so that is obviously the cause of the collision. I'm not sure why that would happen for int vs const int.
comment
created
jacob-carlborg
username_0
In this example there actually is a mismatch between the types. I don’t think it’s the same issue as for structs.
comment
created
kinke
username_2
`const` isn't part of the IR type, but const-ness and thread-local-ness is additionally checked for duplicate global vars, but not part of the error msg: https://github.com/ldc-developers/ldc/blob/9de916b8f63653d6836273d7336615f2e5e9a85e/gen/llvmhelpers.cpp#L1756-L1769

As for mismatching function collisions, we don't have a reference to the original declaration/definition and can't output the first D type (or its LOC etc.).
comment
created
jacob-carlborg
username_0
I would be nice if it could output the D types instead of the LLVM IR types. Perhaps create a mapping of IR types to D types?
comment
created
kinke
username_2
That's not feasible, e.g., an `i32` matches `int`, `uint`, `shared(uint)`, `dchar`, `enum blub : int` etc. Additionally, what matters/is actually checked is the IR type, so that a int/dchar collision isn't detected.
comment
created
jacob-carlborg
username_0
Ok, I see.
comment
closed
kinke
username_2
issue