Skip to content

Commit

Permalink
Don't throw on invalid input in Graph construction (#16575)
Browse files Browse the repository at this point in the history
  • Loading branch information
0101 authored Jan 24, 2024
1 parent ddf057b commit 641d0ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Code generated files with > 64K methods and generated symbols crash when loaded. Use infered sequence points for debugging. ([Issue #16399](https://github.com/dotnet/fsharp/issues/16399), [#PR 16514](https://github.com/dotnet/fsharp/pull/16514))
* `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550))
* Graph Based Checking doesn't throw on invalid parsed input so it can be used for IDE scenarios ([PR #16575](https://github.com/dotnet/fsharp/pull/16575))

### Added

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Driver/GraphChecking/FileContentMapping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let visitSynModuleDecl (decl: SynModuleDecl) : FileContentEntry list =
| SynModuleDecl.NestedModule(moduleInfo = SynComponentInfo(longId = [ ident ]; attributes = attributes); decls = decls) ->
yield! visitSynAttributes attributes
yield FileContentEntry.NestedModule(ident.idText, List.collect visitSynModuleDecl decls)
| SynModuleDecl.NestedModule _ -> failwith "A nested module cannot have multiple identifiers"
| SynModuleDecl.NestedModule _ -> () // A nested module cannot have multiple identifiers. This will already be a parse error, but we could be working with recovered syntax tree
| SynModuleDecl.Let(bindings = bindings) -> yield! List.collect visitBinding bindings
| SynModuleDecl.Types(typeDefns = typeDefns) -> yield! List.collect visitSynTypeDefn typeDefns
| SynModuleDecl.HashDirective _ -> ()
Expand All @@ -80,7 +80,7 @@ let visitSynModuleSigDecl (md: SynModuleSigDecl) =
| SynModuleSigDecl.NestedModule(moduleInfo = SynComponentInfo(longId = [ ident ]; attributes = attributes); moduleDecls = decls) ->
yield! visitSynAttributes attributes
yield FileContentEntry.NestedModule(ident.idText, List.collect visitSynModuleSigDecl decls)
| SynModuleSigDecl.NestedModule _ -> failwith "A nested module cannot have multiple identifiers"
| SynModuleSigDecl.NestedModule _ -> () // A nested module cannot have multiple identifiers. This will already be a parse error, but we could be working with recovered syntax tree
| SynModuleSigDecl.ModuleAbbrev(longId = longId) -> yield! visitLongIdentForModuleAbbrev longId
| SynModuleSigDecl.Val(valSig, _) -> yield! visitSynValSig valSig
| SynModuleSigDecl.Types(types = types) -> yield! List.collect visitSynTypeDefnSig types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,18 @@ module B = C
match content with
| [ TopLevelNamespace "" [ PrefixedIdentifier "C" ] ] -> Assert.Pass()
| content -> Assert.Fail($"Unexpected content: {content}")

[<Test>]
let ``Invalid nested module should just be ignored`` () =
let content =
getContent
false
"""
module A
module B.C
"""

match content with
| [ TopLevelNamespace "" [] ] -> Assert.Pass()
| content -> Assert.Fail($"Unexpected content: {content}")

0 comments on commit 641d0ee

Please sign in to comment.