I'm having trouble with RequireQualifiedAccess: despite the attribute, a union case is shadowing a type. Strangely, the error only appears if I use qualified access on the enclosing module, not inside it or if I open it:
module Module =
type [<RequireQualifiedAccess>] Du =
| SomeCase
type [<RequireQualifiedAccess>] SuperDu =
| Du of Du
let valid = Du.SomeCase // Valid, as expected
let invalid = Module.Du.SomeCase // Not defined?!?
open Module
let validToo = Du.SomeCase // Wait, this is valid again?
In the invalid line, there's first a warning that using .Du
without qualified access is deprecated, as if I were referring to SuperDu.Du
, then it gives an error that SomeCase
is not defined.
I always believed that using open X
is equivalent to prefixing X.
to all definitions taken from that module. But it obviously isn't...?
What is going on here? Do I have to avoid this kind of name collision, despite RequireQualifiedAccess
? Is this a compiler bug?
This is an issue in the F# compiler, which has already been reported. For more information see:
[<RequireQualifiedAccess>]
on a DU shadows types in the same moduleIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With