Please accept my apologies if this is a known issue, but a casual Google search didn't turn up anything, and it's one of those things that are a bit difficult to search for.
Create a new F# library project in Visual Studio 2015.
Add a new code file. As far as I can tell, the name of the file doesn't matter, but for the repro, I called it Dtrs.fs:
namespace Ploeh.Weird.Repro
type Foo = {
Value : string
Text : string }
type Bar = {
Value : string
Number : int }
type Baz = {
Value : int
Text : string }
Notice the namespace: it's important.
Now add _another_ F# library project to the solution.
Reference the first library project from the second project.
Add a new code file to the second library project. Again, I don't think the name of the file matters, but I called mine Client.fs:
module Ploeh.Repro.Client
open Ploeh.Weird.Repro
let b = {
Value = 42
Text = "Ploeh" }
Compile. This code compiles, and the compiler has inferred that b is a value of the type Baz. This is expected, since the expression is unambiguous.
Now go back to the first library project, and add a new code file _below_ the one that contains the three record types. The name of the file doesn't, AFAICT, matter, but you can call it Boo.fs if you'd like (I did). Put this in the file:
namespace Ploeh.Weird.Repro
That's it. Nothing else. This is the same namespace as the file declaring the three record types.
Now compile the solution.
The code still compiles. I'd expect that, since the new file adds no new types (or values).
The code no longer compiles. The compiler gives this error message:
error FS0656: This record contains fields from inconsistent types
This error occurs in the Client.fs file, in the expression that binds to b.
One can work around the issue in a couple of different ways:
Boo.fs file.Boo.fs. For example, it's enough to remove a single character from the namespace declaration to make the code compile again: namespace Ploeh.Weird.Repr.Client.fs: let b : Baz = \....@ploeh Thanks. Yes, I can repro this and it should be fixed. Presumably the "merging" of the two namespace declaration fragments is upsetting the order in which record types are considered when inferring them from field names.
@ploeh I've pushed a PR for a fix for this, link above
Fixed by merged PR above
Most helpful comment
@ploeh Thanks. Yes, I can repro this and it should be fixed. Presumably the "merging" of the two namespace declaration fragments is upsetting the order in which record types are considered when inferring them from field names.