Skip to content

Commit 641d0ee

Browse files
authored
Don't throw on invalid input in Graph construction (#16575)
1 parent ddf057b commit 641d0ee

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* 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))
44
* `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550))
5+
* 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))
56

67
### Added
78

src/Compiler/Driver/GraphChecking/FileContentMapping.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let visitSynModuleDecl (decl: SynModuleDecl) : FileContentEntry list =
5656
| SynModuleDecl.NestedModule(moduleInfo = SynComponentInfo(longId = [ ident ]; attributes = attributes); decls = decls) ->
5757
yield! visitSynAttributes attributes
5858
yield FileContentEntry.NestedModule(ident.idText, List.collect visitSynModuleDecl decls)
59-
| SynModuleDecl.NestedModule _ -> failwith "A nested module cannot have multiple identifiers"
59+
| 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
6060
| SynModuleDecl.Let(bindings = bindings) -> yield! List.collect visitBinding bindings
6161
| SynModuleDecl.Types(typeDefns = typeDefns) -> yield! List.collect visitSynTypeDefn typeDefns
6262
| SynModuleDecl.HashDirective _ -> ()
@@ -80,7 +80,7 @@ let visitSynModuleSigDecl (md: SynModuleSigDecl) =
8080
| SynModuleSigDecl.NestedModule(moduleInfo = SynComponentInfo(longId = [ ident ]; attributes = attributes); moduleDecls = decls) ->
8181
yield! visitSynAttributes attributes
8282
yield FileContentEntry.NestedModule(ident.idText, List.collect visitSynModuleSigDecl decls)
83-
| SynModuleSigDecl.NestedModule _ -> failwith "A nested module cannot have multiple identifiers"
83+
| 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
8484
| SynModuleSigDecl.ModuleAbbrev(longId = longId) -> yield! visitLongIdentForModuleAbbrev longId
8585
| SynModuleSigDecl.Val(valSig, _) -> yield! visitSynValSig valSig
8686
| SynModuleSigDecl.Types(types = types) -> yield! List.collect visitSynTypeDefnSig types

tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/FileContentMappingTests.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,18 @@ module B = C
121121
match content with
122122
| [ TopLevelNamespace "" [ PrefixedIdentifier "C" ] ] -> Assert.Pass()
123123
| content -> Assert.Fail($"Unexpected content: {content}")
124+
125+
[<Test>]
126+
let ``Invalid nested module should just be ignored`` () =
127+
let content =
128+
getContent
129+
false
130+
"""
131+
module A
132+
133+
module B.C
134+
"""
135+
136+
match content with
137+
| [ TopLevelNamespace "" [] ] -> Assert.Pass()
138+
| content -> Assert.Fail($"Unexpected content: {content}")

0 commit comments

Comments
 (0)