Skip to content
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
1799aaf
make attribute targets mismatches a warning and not an error.
edgarfgp Apr 23, 2025
55507e9
release notes
edgarfgp Apr 23, 2025
1738018
update tests
edgarfgp Apr 23, 2025
65f5bb6
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 24, 2025
0c97b9d
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 27, 2025
6f2b706
update baselines
edgarfgp Apr 29, 2025
e8f1bb0
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 29, 2025
75d8f5e
Update baselines
edgarfgp Apr 29, 2025
4f2e97e
Merge branch 'fix-attr-targets' of github.com:edgarfgp/fsharp into fi…
edgarfgp Apr 29, 2025
63be5d5
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 30, 2025
4248f2a
Move attribute form logic to an AP
edgarfgp Apr 30, 2025
cc96217
Merge branch 'main' into fix-attr-targets
edgarfgp May 1, 2025
e270b88
Merge branch 'main' into fix-attr-targets
edgarfgp May 1, 2025
e0cc65a
Merge branch 'main' into fix-attr-targets
edgarfgp May 2, 2025
1e29d58
Merge branch 'main' into fix-attr-targets
edgarfgp May 5, 2025
1470bf9
Merge branch 'main' into fix-attr-targets
edgarfgp May 6, 2025
8988215
Merge branch 'main' into fix-attr-targets
edgarfgp May 7, 2025
74712e8
Merge branch 'main' into fix-attr-targets
edgarfgp May 12, 2025
967c4a9
Merge branch 'main' of github.com:edgarfgp/fsharp
edgarfgp May 13, 2025
a30cef4
Merge branch 'dotnet:main' into main
edgarfgp May 22, 2025
5fa0480
Merge branch 'dotnet:main' into main
edgarfgp May 24, 2025
15e3d34
Merge branch 'dotnet:main' into main
edgarfgp May 29, 2025
b7ffcf8
Merge branch 'dotnet:main' into main
edgarfgp Jun 6, 2025
5bde641
Merge branch 'dotnet:main' into main
edgarfgp Jul 26, 2025
0f7c23c
Merge branch 'dotnet:main' into main
edgarfgp Jul 29, 2025
8f0683d
Check if the module appears to be incorrectly nested based on indenta…
edgarfgp Aug 3, 2025
569b382
one more test
edgarfgp Aug 3, 2025
89ec72a
release notes
edgarfgp Aug 3, 2025
e61b027
Merge branch 'main' into fix-10066
edgarfgp Aug 3, 2025
6074eb5
Merge branch 'main' into fix-10066
edgarfgp Aug 4, 2025
765a7ff
Merge branch 'main' into fix-10066
edgarfgp Aug 6, 2025
a252caf
Move check to ParseHelpers.fs
edgarfgp Aug 6, 2025
fdc5dee
Add LanguageFeature
edgarfgp Aug 6, 2025
72385a6
release notes
edgarfgp Aug 6, 2025
4b01e49
update checkInvalidDeclsInTypeDefn
edgarfgp Aug 6, 2025
9289979
Merge branch 'fix-10066' of github.com:edgarfgp/fsharp into fix-10066
edgarfgp Aug 6, 2025
6a0e283
more tests
edgarfgp Aug 6, 2025
634cddf
Merge branch 'main' into fix-10066
edgarfgp Aug 6, 2025
e2a941a
more tests
edgarfgp Aug 6, 2025
26bd14b
Merge branch 'fix-10066' of github.com:edgarfgp/fsharp into fix-10066
edgarfgp Aug 6, 2025
8354b89
Update tests
edgarfgp Aug 6, 2025
89d9608
Merge branch 'main' into fix-10066
edgarfgp Aug 6, 2025
0acdd53
Merge branch 'main' into fix-10066
edgarfgp Aug 6, 2025
0f1c26f
Update src/Compiler/SyntaxTree/ParseHelpers.fs
edgarfgp Aug 9, 2025
b98dbdf
Revert "Update src/Compiler/SyntaxTree/ParseHelpers.fs"
edgarfgp Aug 11, 2025
a9e53fa
Merge branch 'main' into fix-10066
edgarfgp Aug 11, 2025
f7b4c2c
Merge branch 'main' into fix-10066
edgarfgp Aug 12, 2025
bdf8a93
Use LexFilter instead ParseHelper to raise the warnings.
edgarfgp Aug 13, 2025
0b46a40
Update baselines
edgarfgp Aug 13, 2025
6a9ddd9
update tests
edgarfgp Aug 13, 2025
3c00990
No warning - all declarations at same indentation level
edgarfgp Aug 13, 2025
cca0cc8
Update FSComp.txt
edgarfgp Aug 13, 2025
399755a
Add more tests and rename feature flag
edgarfgp Aug 14, 2025
20cd646
update tests
edgarfgp Aug 14, 2025
f625bbb
Update tests
edgarfgp Aug 14, 2025
b55be44
more renaming
edgarfgp Aug 14, 2025
3a37b06
use a simple function instead of an AP
edgarfgp Aug 14, 2025
7585e04
simplify and update baselines
edgarfgp Aug 14, 2025
9589158
update baselines
edgarfgp Aug 14, 2025
efe20da
fix indentation issue found thanks to the new error
edgarfgp Aug 14, 2025
7642629
update release notes
edgarfgp Aug 14, 2025
a412c6b
more bsl
edgarfgp Aug 15, 2025
adcd373
more test updates
edgarfgp Aug 15, 2025
46a9848
Merge branch 'main' into fix-10066
edgarfgp Aug 15, 2025
0a9331a
update tests
edgarfgp Aug 19, 2025
e42398c
fix bsl
edgarfgp Aug 20, 2025
66dbfa2
Merge branch 'main' into fix-10066
edgarfgp Aug 25, 2025
3e18765
Merge branch 'main' into fix-10066
edgarfgp Aug 25, 2025
413a200
Merge branch 'main' into fix-10066
edgarfgp Aug 26, 2025
682cf51
Merge branch 'main' into fix-10066
edgarfgp Aug 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Completion: fix previous namespace considered opened [PR #18609](https://github.com/dotnet/fsharp/pull/18609)
* Fix active pattern typechecking regression. ([Issue #18638](https://github.com/dotnet/fsharp/issues/18638), [PR #18642](https://github.com/dotnet/fsharp/pull/18642))
* Fix nullness warnings when casting non-nullable values to `IEquatable<T>` to match C# behavior. ([Issue #18759](https://github.com/dotnet/fsharp/issues/18759))
* Warn when a module definition is encountered inside a type definition.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813))
* Fix IsByRefLikeAttribute types being incorrectly suppressed in completion lists. Types like `Span<T>` and `ReadOnlySpan<T>` now appear correctly in IntelliSense.

### Changed
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
### Fixed

* Warn on uppercase identifiers in patterns. ([PR #15816](https://github.com/dotnet/fsharp/pull/15816))
* Warn when a module definition is encountered inside a type definition.([Issue #10066](https://github.com/dotnet/fsharp/issues/10066), [PR #18813](https://github.com/dotnet/fsharp/pull/18813))

### Changed
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,7 @@ featureSupportWarnWhenUnitPassedToObjArg,"Warn when unit is passed to a member a
featureUseBangBindingValueDiscard,"Allows use! _ = ... in computation expressions"
featureBetterAnonymousRecordParsing,"Support for better anonymous record parsing"
featureScopedNowarn,"Support for scoped enabling / disabling of warnings by #warn and #nowarn directives, also inside modules"
featureWarnOnUnexpectedModuleDefinitionsInsideTypes,"Warn when a module definition is encountered inside a type definition"
featureAllowLetOrUseBangTypeAnnotationWithoutParens,"Allow let! and use! type annotations without requiring parentheses"
3874,lexWarnDirectiveMustBeFirst,"#nowarn/#warnon directives must appear as the first non-whitespace characters on a line"
3875,lexWarnDirectiveMustHaveArgs,"Warn directives must have warning number(s) as argument(s)"
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type LanguageFeature =
| UseBangBindingValueDiscard
| BetterAnonymousRecordParsing
| ScopedNowarn
| WarnOnUnexpectedModuleDefinitionsInsideTypes
| AllowTypedLetUseAndBang
| ReturnFromFinal

Expand Down Expand Up @@ -243,6 +244,7 @@ type LanguageVersion(versionText) =

// F# preview (still preview in 10.0)
LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work
LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes, previewVersion
]

static let defaultLanguageVersion = LanguageVersion("default")
Expand Down Expand Up @@ -410,6 +412,7 @@ type LanguageVersion(versionText) =
| LanguageFeature.UseBangBindingValueDiscard -> FSComp.SR.featureUseBangBindingValueDiscard ()
| LanguageFeature.BetterAnonymousRecordParsing -> FSComp.SR.featureBetterAnonymousRecordParsing ()
| LanguageFeature.ScopedNowarn -> FSComp.SR.featureScopedNowarn ()
| LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes -> FSComp.SR.featureWarnOnUnexpectedModuleDefinitionsInsideTypes ()
| LanguageFeature.AllowTypedLetUseAndBang -> FSComp.SR.featureAllowLetOrUseBangTypeAnnotationWithoutParens ()
| LanguageFeature.ReturnFromFinal -> FSComp.SR.featureReturnFromFinal ()

Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type LanguageFeature =
| UseBangBindingValueDiscard
| BetterAnonymousRecordParsing
| ScopedNowarn
| WarnOnUnexpectedModuleDefinitionsInsideTypes
| AllowTypedLetUseAndBang
| ReturnFromFinal

Expand Down
33 changes: 33 additions & 0 deletions src/Compiler/SyntaxTree/ParseHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,39 @@ let leadingKeywordIsAbstract =
| SynLeadingKeyword.StaticAbstractMember _ -> true
| _ -> false

[<return: Struct>]
let (|NestedModuleAt|_|) =
function
| SynModuleDecl.NestedModule(trivia = { ModuleKeyword = Some mKeyword }) -> ValueSome mKeyword
| _ -> ValueNone

[<return: Struct>]
let (|TypesFollowedByModules|_|) =
function
| [ SynModuleDecl.Types(typeDefns = defns) ], rest -> ValueSome(defns, rest)
| _ -> ValueNone

let getLastTypeColumn (defns: SynTypeDefn list) =
defns
|> List.choose (function
| SynTypeDefn(trivia = { LeadingKeyword = mKeyword }) -> Some mKeyword.Range)
|> List.tryLast
|> Option.defaultValue range0

let checkInvalidDeclsInTypeDefn (moduleDecls1: SynModuleDecl list) (moduleDecls2: SynModuleDecl list) (lexBuf: Lexbuf) =
match moduleDecls1, moduleDecls2 with
| TypesFollowedByModules(defns, rest) ->
let lastTypeColumn = getLastTypeColumn defns

for defn in rest do
match defn with
| NestedModuleAt mKeyword ->
if lexBuf.SupportsFeature(LanguageFeature.WarnOnUnexpectedModuleDefinitionsInsideTypes) then
if mKeyword.StartColumn > lastTypeColumn.StartColumn then
warning (Error(FSComp.SR.parsInvalidDeclarationSyntax (), mKeyword))
| _ -> ()
| _ -> ()

/// Unified helper for creating let/let!/use/use! expressions
/// Creates either SynExpr.LetOrUse or SynExpr.LetOrUseBang based on isBang parameter
/// Handles all four cases: 'let', 'let!', 'use', and 'use!'
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/SyntaxTree/ParseHelpers.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open FSharp.Compiler.Syntax
open FSharp.Compiler.SyntaxTrivia
open FSharp.Compiler.Features
open FSharp.Compiler.Text
open FSharp.Compiler.UnicodeLexing
open FSharp.Compiler.Xml
open Internal.Utilities.Text.Lexing
open Internal.Utilities.Text.Parsing
Expand Down Expand Up @@ -270,3 +271,7 @@ val mkSynField:
SynField

val leadingKeywordIsAbstract: SynLeadingKeyword -> bool

/// Check for invalid declarations inside type definitions
val checkInvalidDeclsInTypeDefn:
moduleDecls1: SynModuleDecl list -> moduleDecls2: SynModuleDecl list -> lexBuf: Lexbuf -> unit
7 changes: 6 additions & 1 deletion src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -1271,8 +1271,13 @@ moduleDefnsOrExpr:

/* A sequence of definitions in a namespace or module */
moduleDefns:
| moduleDefnOrDirective moduleDefnOrDirective
{ checkInvalidDeclsInTypeDefn $1 $2 parseState.LexBuffer
$1 @ $2 }

| moduleDefnOrDirective moduleDefns
{ $1 @ $2 }
{ checkInvalidDeclsInTypeDefn $1 $2 parseState.LexBuffer
$1 @ $2 }

| moduleDefnOrDirective topSeparators moduleDefnsOrExpr
{ $1 @ $3 }
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace ErrorMessages

open Xunit
open FSharp.Test.Compiler

module ``Module definition is encountered inside a type definition`` =

[<Fact>]
let ``Warn when a module definition is encountered inside a type definition``() =
Fsx """
type IFace =
abstract F : int -> int
module M =
let f () = ()

type C () =
member _.F () = 3
module M2 =
let f () = ()

type U =
| A
| B
module M3 =
let f () = ()

type R =
{ A : int }
module M4 =
let f () = ()

type A = A

module M4 = begin end
module M5 = begin end
module M6 = begin end

type B =
| B
module M7 = begin end
module M8 = begin end
module M9 = begin end

module ThisIsFine =
let f () = ()

type D = D
"""
|> withLangVersionPreview
|> typecheck
|> shouldFail
|> withDiagnostics [
(Warning 554, Line 31, Col 5, Line 31, Col 11, "Invalid declaration syntax")
(Warning 554, Line 32, Col 5, Line 32, Col 11, "Invalid declaration syntax")
(Warning 554, Line 33, Col 5, Line 33, Col 11, "Invalid declaration syntax")
(Warning 554, Line 20, Col 5, Line 20, Col 11, "Invalid declaration syntax")
(Warning 554, Line 15, Col 5, Line 15, Col 11, "Invalid declaration syntax")
(Warning 554, Line 9, Col 5, Line 9, Col 11, "Invalid declaration syntax");
(Warning 554, Line 4, Col 5, Line 4, Col 11, "Invalid declaration syntax")
]

[<Fact>]
let ``Don't warn when a module definition is encountered inside a type definition``() =
Fsx """
type IFace =
abstract F : int -> int
module M =
let f () = ()

type C () =
member _.F () = 3
module M2 =
let f () = ()

type U =
| A
| B
module M3 =
let f () = ()

type R =
{ A : int }
module M4 =
let f () = ()

type A = A

module M5 = begin end
module M6 = begin end
module M7 = begin end

type B =
| B
module M8 = begin end
module M9 = begin end
module M10 = begin end

module ThisIsFine =
let f () = ()

type D = D
"""
|> withLangVersion10
|> typecheck
|> shouldSucceed
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<Compile Include="ErrorMessages\FS0988AtEndOfFile.fs" />
<Compile Include="ErrorMessages\Repro1548.fs" />
<Compile Include="ErrorMessages\WarnIfDiscardedInList.fs" />
<Compile Include="ErrorMessages\WarnOnUnexpectedModuleDefinitions.fs" />
<Compile Include="ErrorMessages\UnionCasePatternMatchingErrors.fs" />
<Compile Include="ErrorMessages\InterfaceImplInAugmentationsTests.fs" />
<Compile Include="ErrorMessages\ExtendedDiagnosticDataTests.fs" />
Expand Down
Loading
Loading