Skip to content

Regression on SDK 5.0.300: When using an identifier like __SOURCE_DIRECTORY__ in a type parameter one get FS3045 compilation error. #11610

Closed

Description

@da9l

Please provide a succinct description of the issue.

When using SDK 5.0.300 and one uses an identifier in a type parameter one get a FS3045 compilation error.
It works on SDK 5.0.203

Provide the steps required to reproduce the problem:

  1. Use SDK 5.0.300
  2. Compile the code below, also see FS3045 error reproduction repro
open System
open FSharp.Data

type Sample = XmlProvider<Schema="Sample.xsd",
                          ResolutionFolder=__SOURCE_DIRECTORY__>

Expected behavior

It should work as it does in SDK 5.0.203.

Actual behavior

A FS3045 compilation error.

Known workarounds

  1. Use SDK 5.0.203
  2. Put the identifier into a [<Literal>] value.
[<Literal>]
let refDir = __SOURCE_DIRECTORY__
type Sample = XmlProvider<Schema="Sample.xsd",
                          ResolutionFolder=refDir>

Provide any related information (optional):

  • Operating system: Windows 10
  • .NET Runtime kind (.NET Core, .NET Framework, Mono): dotnet-sdk 5.0.300
  • Editing Tools (e.g. Visual Studio Version, Visual Studio): Visual Studio Code (probably not related)

Activity

  1. nbevans commented on May 28, 2021

    @nbevans

    Seeing something similar in a .fsx

    image

  2. self-assigned this
    on May 29, 2021
  3. cartermp commented on May 29, 2021

    @cartermp
    Contributor

    Self-assigning myself to triage and determine if there was a regression when the holiday is over.

  4. added this to the Backlog milestone on Jun 3, 2021
  5. added
    Impact-High
    on Jun 3, 2021
  6. cartermp commented on Jun 3, 2021

    @cartermp
    Contributor

    Confirmed regression, this breaks numerous scripts

  7. modified the milestones: Backlog, 17.0 on Jun 4, 2021
  8. cartermp commented on Jun 4, 2021

    @cartermp
    Contributor

    Tagging @vzarytovskii, we use __SOURCE_DIRECTORY__ quite heavily in our test scripts, and in our .NET 6 build of the repo these don't fail. So we'll want to determine if this is actually us, or if there was some regression that slipped into the most recent .NET SDK.

  9. vzarytovskii commented on Jun 4, 2021

    @vzarytovskii
    Member

    Interestingly, enough, it seems to be not working in the given type provider, but works fine in, for example, attributes.

    __SOURCE_DIRECTORY__ has a special treatment by the lexer (it is essentially a compiler-generated literal), which turns into path |> GetDirectoryName() call:

    let KeywordOrIdentifierToken args (lexbuf:Lexbuf) s =
    match keywordTable.TryGetValue s with
    | true, v ->
    match v with
    | RESERVED ->
    warning(ReservedKeyword(FSComp.SR.lexhlpIdentifierReserved(s), lexbuf.LexemeRange))
    IdentifierToken args lexbuf s
    | _ -> v
    | _ ->
    match s with
    | "__SOURCE_DIRECTORY__" ->
    let filename = FileIndex.fileOfFileIndex lexbuf.StartPos.FileIndex
    let dirname =
    if String.IsNullOrWhiteSpace(filename) then
    String.Empty
    else if filename = stdinMockFilename then
    System.IO.Directory.GetCurrentDirectory()
    else
    filename
    |> FileSystem.GetFullPathShim (* asserts that path is already absolute *)
    |> System.IO.Path.GetDirectoryName
    if String.IsNullOrEmpty dirname then dirname
    else PathMap.applyDir args.pathMap dirname
    |> fun dir -> KEYWORD_STRING(s, dir)

    I am going to see why it is not available when running a type provider.
    It is interesting, though, that it regressed from 5.0.203.

    Edit: this may be a related change: b1fa258#diff-c2bb91ab9348d741a90e5e1774d06a000d1613b6a50e47af8a24cdcd60cb1217

  10. added a commit that references this issue on Jun 7, 2021
  11. CaptnCodr commented on Jun 16, 2021

    @CaptnCodr
    Contributor

    When is this fix available? I have v5.0.301 installed and get this error.

  12. vzarytovskii commented on Jun 16, 2021

    @vzarytovskii
    Member

    @CaptnCodr i think we merged it after 5.0.301 was preparing for release, unfortunately :(
    @cartermp do you know when it may be released? Not sure if we got it into 16.11/16.10 (I don't see any merges since the fix landed in main, on dev17).

  13. cartermp commented on Jun 16, 2021

    @cartermp
    Contributor

    Should be in the next month, so long as the SDK also releases around then.

  14. cartermp commented on Jun 16, 2021

    @cartermp
    Contributor

    Note that our insertions for dev17 aren't working yet, so we're quite a bit behind. And there's no autoamtic insertions into 16.11, so we need to service the fix.

  15. Swoorup commented on Jul 16, 2021

    @Swoorup
    Contributor

    Looks like isn't fixed for 5.0.302 as well?

  16. vzarytovskii commented on Jul 16, 2021

    @vzarytovskii
    Member

    Looks like isn't fixed for 5.0.302 as well?

    Good question. I'm not entirely sure what went into 302. @KevinRansom @brettfo what's the easiest way to tell which commit 302 is?

  17. nhirschey commented on Aug 13, 2021

    @nhirschey
    Contributor

    This is still broken in 5.0.400.

    dotnet5 0 400

    #r "nuget: FSharp.Data,4.2.2"
    
    open FSharp.Data
    
    let lines = ["A,B";"1,2"]
    System.IO.File.WriteAllLines("test.csv", lines)
    
    // Does not work
    type Test = CsvProvider<__SOURCE_DIRECTORY__ + "/test.csv",ResolutionFolder= __SOURCE_DIRECTORY__>
    Test.GetSample()
    
    // This works
    let [<Literal>] SourceDir = __SOURCE_DIRECTORY__
    type Test2 = CsvProvider<"test.csv",ResolutionFolder= SourceDir>
    Test2.GetSample()
  18. reopened this on Aug 13, 2021
  19. dsyme commented on Aug 13, 2021

    @dsyme
    Contributor

    @nhirschey Yes it looks like the fix isn't in the release branch for 16.11, which is a shame

    https://github.com/dotnet/fsharp/commits/release/dev16.11

    We're after this commit: 78826fd

    The fix will certainly be in .NET 6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Impact-HighRegression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions