dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.92k stars 786 forks source link

Pseudo namespace "global" fails when used with specifying record fields, and acts odd with DU fields #10282

Open abelbraaksma opened 4 years ago

abelbraaksma commented 4 years ago

The ways in which global as pseudo-namespace can be used are murky:

Repro steps

Use of global with DU fields:

This works (susprisingly so, but I do see some logic in allowing this):

type MyDU = X of string

module Test =
    let useGlobalPrefix = global.X "foo"   // succeeds

This does not (but should):

type MyDU = X of string

module Test =
    let useGlobalPrefix = global.MyDU.X "foo"   // fails

The above should work on the grounds that MyDU.X "foo" is valid syntax, and in the root namespace, meaning I should be able to prefix it with global.

Use of global with record fields

Using global never works when used with record fields.

type MyRec = { A : string }

module Test =
    let useGlobalPrefix1 = { global.MyRec.A = "foo" }   // fails
    let useGlobalPrefix2 = { global.A = "foo" }       // fails

Expected behavior

Use of global should be accepted as it is there to be able to distinguish conflicting qualified names through their full path. Whether or not I put the above code in a namespace, it fails when prefixed with global and used on a field.

Actual behavior

It shows an error which tells me what I should do with global, but I actually already did:

error FS1126: 'global' may only be used as the first name in a qualified path

Known workarounds

Use type aliases: the problem does not happen is you alias a type with global as the prefix.

cartermp commented 3 years ago

Tracking as a bug, perhaps it's more of a feature improvement but I won't be terribly pedantic about that since this is unexpected behavior.