fsprojects / fsprojects/FSharpLint

net7.0 projects fail to parse (with exception generated at RedundantNewKeyword rule, msg `'IDisposable' required here is not available. You should add a reference to the assembly "netstandard"...`)

Open
#598 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
F#
Stars
327
Forks
74
PR merge metrics
No merged PRs in 30d

Description

Description

dotnet fsharplint lint .\FsLintBug.fsproj - fails with "Failed to parse file"

Repro steps
Code to reproduce the problem:

FsLintBug.fsproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="LibGit2Sharp" Version="0.26.2" />
  </ItemGroup>
</Project>

Program.fs

open LibGit2Sharp

printfn "Hello from F#"

let pathToGitRepository = "some-path"
let repo = new Repository(pathToGitRepository) // fails with "Failed to parse file"
// let repo = Repository(pathToGitRepository) // ok
Commands:

dotnet build - ok
dotnet fsharplint lint .\FsLintBug.fsproj - fails with "Failed to parse file":

Failed to parse file Program.fs
Exception Message:
The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: The type 'IDisposable' required here is not available. You should add a reference to the assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".)
Exception Stack Trace:
   at FSharp.Compiler.ErrorLogger.ErrorLoggerExtensions.ErrorLogger.Error[b](ErrorLogger x, Exception exn) in D:\workspace\_work\1\s\src\fsharp\ErrorLogger.fs:line 390
   at FSharp.Compiler.Import.ImportTypeRefData(ImportMap env, Range m, ILScopeRef scoref, String[] path, String typeName) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 106
   at FSharp.Compiler.Import.ImportILTypeRefUncached(ImportMap env, Range m, ILTypeRef tref) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 143
   at FSharp.Compiler.Import.ImportILTypeRef(ImportMap env, Range m, ILTypeRef tref) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 151
   at FSharp.Compiler.Import.ImportILType(ImportMap env, Range m, FSharpList`1 tinst, ILType ty) in D:\workspace\_work\1\s\src\fsharp\import.fs:line 180
   at FSharp.Compiler.Infos.getInterfaces@125-3.Invoke(ILType ity) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 127
   at Microsoft.FSharp.Primitives.Basics.List.chooseToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 xs) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 178
   at Microsoft.FSharp.Primitives.Basics.List.choose[T,TResult](FSharpFunc`2 f, FSharpList`1 xs) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 193
   at Microsoft.FSharp.Collections.ListModule.Choose[T,TResult](FSharpFunc`2 chooser, FSharpList`1 list) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 155
   at FSharp.Compiler.Infos.GetImmediateInterfacesOfType(SkipUnrefInterfaces skipUnref, TcGlobals g, ImportMap amap, Range m, TType ty) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 150
   at FSharp.Compiler.Infos.loop@185-42[a](Boolean followInterfaces, AllowMultiIntfInstantiations allowMultiIntfInst, SkipUnrefInterfaces skipUnref, FSharpFunc`2 visitor, TcGlobals g, ImportMap amap, Range m, Int32 ndeep, TType ty, Tuple`3 state) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 239
   at FSharp.Compiler.Infos.FoldHierarchyOfTypeAux[a](Boolean followInterfaces, AllowMultiIntfInstantiations allowMultiIntfInst, SkipUnrefInterfaces skipUnref, FSharpFunc`2 visitor, TcGlobals g, ImportMap amap, Range m, TType ty, a acc) in D:\workspace\_work\1\s\src\fsharp\lib.fs:line 256
   at FSharp.Compiler.Infos.AllSuperTypesOfType(TcGlobals g, ImportMap amap, Range m, AllowMultiIntfInstantiations allowMultiIntfInst, TType ty) in D:\workspace\_work\1\s\src\fsharp\infos.fs:line 282
   at <StartupCode$FSharp-Compiler-Service>.$Symbols.get_AllInterfaces@588.GenerateNext(IEnumerable`1& next) in D:\workspace\_work\1\s\src\fsharp\symbols\Symbols.fs:line 588
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\seqcore.fs:line 368
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System.Collections.IEnumerator.MoveNext() in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\seqcore.fs:line 400
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at FSharp.Compiler.Symbols.FSharpEntity.get_AllInterfaces() in D:\workspace\_work\1\s\src\fsharp\symbols\Symbols.fs:line 587
   at FSharpLint.Rules.RedundantNewKeyword.doesNotImplementIDisposable(FSharpCheckFileResults checkFile, LongIdentWithDots ident, Unit unitVar0) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Rules\Conventions\RedundantNewKeyword.fs:line 32
   at Microsoft.FSharp.Collections.ListModule.Fold[T,TState](FSharpFunc`2 folder, TState state, FSharpList`1 list) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 222
   at FSharpLint.Application.Lint.typeCheckSuggestion@249.Invoke(LintWarning suggestion) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Application\Lint.fs:line 249
   at Microsoft.FSharp.Collections.Internal.IEnumerator.choose@171.System.Collections.IEnumerator.MoveNext() in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 179
   at Microsoft.FSharp.Collections.SeqModule.Iterate[T](FSharpFunc`2 action, IEnumerable`1 source) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 496
   at FSharpLint.Application.Lint.lint(LintInfo lintInfo, FileParseInfo fileInfo) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Core\Application\Lint.fs:line 243
Expected behavior

No parse errors, just warning as expected

========== Linting Program.fs ==========
Usage of `new` keyword here is redundant.
Error on line * starting at column *
    let repo = new Repository(options.Repo)
Actual behavior

fails with "Failed to parse file"

Known workarounds

Don't use redundant new` keyword.

let repo = new Repository(pathToGitRepository) // fails with "Failed to parse file"
// let repo = Repository(pathToGitRepository) // ok
Related information

Package Id Version Commands

dotnet-fsharplint 0.21.3 dotnet-fsharplint

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the FsLintBug.fsproj and Program.fs example using dotnet fsharplint lint .\FsLintBug.fsproj. Start in src/FSharpLint.Core/Rules/Conventions/RedundantNewKeyword.fs, especially the doesNotImplementIDisposable path shown in the trace. Done means the redundant new usage produces a warning without a parse error, while the non-new form remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.