Null reference exception in compiler when referencing duplicate type defined in another project
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
When a project has two types with the same name in the same namespace defined in two separate files, and the second of the two definitions is referenced in another project, I see `error FS0193: internal error: Object reference not set to an instance of an object`, indicating a null reference exception somewhere in the compiler. If I reference the first definition, I get `error FS0039: The value or constructor 'T1' is not defined`. I would expect the latter error in both cases.
**Repro steps**
Provide the steps required to reproduce the problem:
1. Create two projects, e.g., project A and project B.
2. Reference project A in project B.
3. Create two types with the same name in the same namespace in project A.
4. Reference the second type definition in project B (call a method on it, use a constructor, etc.).
5. Get `error FS0193: internal error: Object reference not set to an instance of an object`.
Minimal repro: https://gist.github.com/brianrourkeboll/169502b7cd20ec41f84a59cc0559b4b4
#### A/T1.fs
```fsharp
namespace A
type T = T1
```
#### A/T2.fs
```fsharp
namespace A
type T = T2
```
#### B/Program.fs
```fsharp
open A
let _ = T1 // FS0039: The value or constructor 'T1' is not defined.
let _ = T2 // FS0193: internal error: Object reference not set to an instance of an object.
```
**Expected behavior**
I would expect to see `error FS0249: Two type definitions named 'T' occur in namespace 'A' in two parts of this assembly` in project A and `error FS0039: The value or constructor 'T1' is not defined` in project B when referencing either of the duplicate types.
**Actual behavior**
I do see `error FS0249: Two type definitions named 'T' occur in namespace 'A' in two parts of this assembly` in project A, but I see `error FS0193: internal error: Object reference not set to an instance of an object` when I reference the second of the two duplicate types in project B.
**Related information**
I see this in Visual Studio 17.9.3 and 17.10.0 Preview 2, as well as in VS Code with Ionide with .NET SDK 8.0.202. I'm not sure how long this behavior has been around.
Contributor guide
Assessment
This issue has not been assessed yet.