Skip to content

Getting a 'no Oak node is defined for this type' error when formatting a p/invoke signature with nullability annotations #3414

Description

@Numpsy

I tried to use Fantomas online to report this, but got a github error about the URL being too long, so:

I tried to run Fantomas (both 7 and the 8 preview) on a new project at work and got the error

Failed to format file: .\src\Fortra.DCS.Metadata.FileSystem\XAttr.fs : no Oak node is defined for this type: App
  (LongIdent (SynLongIdent ([byte], [], [None])), None, [], [], None, false,
   (19,65--19,69))
At line 19, column 65 in tmp.fsx.

Which appears to be down to code like this

module private XAttrHandler =

    [<SupportedOSPlatform("macos")>]
    [<DllImport("/usr/lib/libSystem.dylib", EntryPoint = "getxattr", SetLastError = true)>]
    extern int64 private getxattrMacOs(string path, string name, byte[] | null value, uint64 size, uint32 position, int options)

If I try to format that in Fantomas online I get this error:

System.Exception: unexpected type: App
  (LongIdent (SynLongIdent ([byte], [], [None])), None, [], [], None, false,
   (5,65--5,69))
   at Fantomas.Core.ASTTransformer.mkType(CreationAide creationAide, SynType t) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2419
   at Fantomas.Core.ASTTransformer.mkType(CreationAide creationAide, SynType t) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2330
   at Fantomas.Core.ASTTransformer.mkType(CreationAide creationAide, SynType t) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2418
   at Fantomas.Core.ASTTransformer.mkExternType@2007.Invoke(SynType t) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2033
   at Fantomas.Core.ASTTransformer.mkExternPat@2036.Invoke(SynPat pat) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2040
   at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\local.fs:line 240
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\local.fs:line 250
   at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 list) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\list.fs:line 98
   at Fantomas.Core.ASTTransformer.mkExternBinding(CreationAide creationAide, SynBinding _arg8) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2053
   at Fantomas.Core.ASTTransformer.mkModuleDecl(CreationAide creationAide, SynModuleDecl decl) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2099
   at Fantomas.Core.ASTTransformer.mkModuleDecls@3278-5.Invoke(FSharpList`1 nodes) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3278
   at Fantomas.Core.ASTTransformer.mkModuleDecl(CreationAide creationAide, SynModuleDecl decl) in /_//src/Fantomas.Core/ASTTransformer.fs:line 2113
   at Fantomas.Core.ASTTransformer.mkModuleDecls@3278-5.Invoke(FSharpList`1 nodes) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3278
   at Fantomas.Core.ASTTransformer.mkModuleOrNamespace(CreationAide creationAide, SynModuleOrNamespace mn) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3343
   at Fantomas.Core.ASTTransformer.mds@3353.Invoke(SynModuleOrNamespace mn)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\local.fs:line 247
   at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 list) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\list.fs:line 98
   at Fantomas.Core.ASTTransformer.mkImplFile(CreationAide creationAide, ParsedImplFileInput _arg15, Range m) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3353
   at Fantomas.Core.ASTTransformer.mkOak(FSharpOption`1 sourceText, ParsedInput ast) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3795
   at Fantomas.Core.CodeFormatterImpl.formatDocument@114-3.Invoke(Unit unitVar) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 114
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\async.fs:line 509
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\async.fs:line 112

The error goes away if I change the byte[] | null to just byte[].

Thanks.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions