Skip to content

Commit

Permalink
Merge pull request #15621 from dotnet/merges/main-to-release/dev17.8
Browse files Browse the repository at this point in the history
Merge main to release/dev17.8
  • Loading branch information
KevinRansom authored Jul 19, 2023
2 parents 66a124d + f5f8fcb commit ed74744
Show file tree
Hide file tree
Showing 68 changed files with 674 additions and 188 deletions.
1 change: 1 addition & 0 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ module MutRecBindingChecking =
let innerState = (incrClassCtorLhsOpt, envForTycon, tpenv, recBindIdx, uncheckedBindsRev)
[Phase2AIncrClassBindings (tcref, letBinds, isStatic, isRec, m)], innerState

| SynMemberDefn.Member(SynBinding(headPat = SynPat.Wild _; expr = SynExpr.ArbitraryAfterError _), _), _
| SynMemberDefn.Member(SynBinding(headPat = SynPat.FromParseError(SynPat.Wild _, _)), _), _ ->
[], innerState

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3930,7 +3930,7 @@ let GetInstanceMemberThisVariable (vspec: Val, expr) =
// Skip over LAM tps. Choose 'a.
if vspec.IsInstanceMember then
let rec firstArg e =
match stripDebugPoints e with
match stripDebugPoints e with
| Expr.TyLambda (_, _, b, _, _) -> firstArg b
| Expr.TyChoose (_, b, _) -> firstArg b
| Expr.Lambda (_, _, _, [v], _, _, _) -> Some v
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ type PhasedDiagnostic with
match x.Exception with
| DiagnosticEnabledWithLanguageFeature (_, _, _, enabled) -> enabled
| _ ->
(severity = FSharpDiagnosticSeverity.Info)
(severity = FSharpDiagnosticSeverity.Info && level > 0)
|| (severity = FSharpDiagnosticSeverity.Warning && level >= x.WarningLevel)

/// Indicates if a diagnostic should be reported as an informational
Expand Down
1 change: 0 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,6 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
3351,chkFeatureNotRuntimeSupported,"Feature '%s' is not supported by target runtime."
3352,typrelInterfaceMemberNoMostSpecificImplementation,"Interface member '%s' does not have a most specific implementation."
3353,chkFeatureNotSupportedInLibrary,"Feature '%s' requires the F# library for language version %s or greater."
3360,parsEqualsMissingInTypeDefinition,"Unexpected token in type definition. Expected '=' after the type '%s'."
useSdkRefs,"Use reference assemblies for .NET framework references when available (Enabled by default)."
optsGetLangVersions,"Display the allowed values for language version."
optsSetLangVersion,"Specify language version such as 'latest' or 'preview'."
Expand Down
18 changes: 18 additions & 0 deletions src/Compiler/Service/FSharpParseFileResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,24 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
let result = SyntaxTraversal.Traverse(pos, input, visitor)
result.IsSome

member _.IsPositionWithinTypeDefinition pos =
let visitor =
{ new SyntaxVisitorBase<_>() with
override _.VisitComponentInfo(path, _) =
let typeDefs =
path
|> List.filter (function
| SyntaxNode.SynModule (SynModuleDecl.Types _) -> true
| _ -> false)

match typeDefs with
| [] -> None
| _ -> Some true
}

let result = SyntaxTraversal.Traverse(pos, input, visitor)
result.IsSome

member _.IsBindingALambdaAtPosition pos =
let visitor =
{ new SyntaxVisitorBase<_>() with
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Service/FSharpParseFileResults.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type public FSharpParseFileResults =
/// Determines if the expression or pattern at the given position has a type annotation
member IsTypeAnnotationGivenAtPosition: pos -> bool

/// Determines if the given position is bound to a type definition
member IsPositionWithinTypeDefinition: pos -> bool

/// Determines if the binding at the given position is bound to a lambda expression
member IsBindingALambdaAtPosition: pos -> bool

Expand Down
38 changes: 17 additions & 21 deletions src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -1588,24 +1588,6 @@ tyconDefn:
let trivia: SynTypeDefnTrivia = { LeadingKeyword = leadingKeyword; EqualsRange = None; WithKeyword = None }
SynTypeDefn($1, SynTypeDefnRepr.Simple(SynTypeDefnSimpleRepr.None($1.Range), $1.Range), [], None, $1.Range, trivia) }

| typeNameInfo opt_equals tyconDefnRhsBlock
{ match $2 with
| Some _ -> ()
| None ->
let (SynComponentInfo(_, _, _, lid, _, _, _, _)) = $1
// While the spec doesn't allow long idents here, the parser doesn't enforce this, so take one ident
let typeNameId = List.last lid
raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsEqualsMissingInTypeDefinition(typeNameId.ToString()))

let nameRange = rhs parseState 1
let (tcDefRepr: SynTypeDefnRepr), mWith, members = $3 nameRange
let declRange = unionRanges (rhs parseState 1) tcDefRepr.Range
let mWhole = (declRange, members) ||> unionRangeWithListBy (fun (mem: SynMemberDefn) -> mem.Range)

fun leadingKeyword ->
let trivia: SynTypeDefnTrivia = { LeadingKeyword = leadingKeyword; EqualsRange = $2; WithKeyword = mWith }
SynTypeDefn($1, tcDefRepr, members, None, mWhole, trivia) }

| typeNameInfo tyconDefnAugmentation
{ let mWithKwd, classDefns = $2
let m = (rhs parseState 1, classDefns) ||> unionRangeWithListBy (fun mem -> mem.Range)
Expand All @@ -1632,11 +1614,21 @@ tyconDefn:

let tcDefRepr =
match tcDefRepr, memberCtorPattern with
| SynTypeDefnRepr.Simple(SynTypeDefnSimpleRepr.None _, m), Some ctor ->
reportParseErrorAt m (FSComp.SR.parsEmptyTypeDefinition())
SynTypeDefnRepr.ObjectModel(SynTypeDefnKind.Unspecified, [ctor], unionRanges m mEquals)

| SynTypeDefnRepr.Simple(SynTypeDefnSimpleRepr.None mName, m), _ ->
reportParseErrorAt m (FSComp.SR.parsEmptyTypeDefinition())
tcDefRepr

| SynTypeDefnRepr.ObjectModel(k, cspec, m), Some ctor ->
SynTypeDefnRepr.ObjectModel(k, ctor :: cspec, m)

| _, Some ctor ->
reportParseErrorAt (rhs2 parseState 1 5) (FSComp.SR.parsOnlyClassCanTakeValueArguments ())
tcDefRepr

| _ ->
match az with
| Some(_, Some id) ->
Expand Down Expand Up @@ -1685,7 +1677,7 @@ tyconDefn:

fun leadingKeyword ->
let trivia = { SynTypeDefnTrivia.Zero with LeadingKeyword = leadingKeyword }
SynTypeDefn($1, SynTypeDefnRepr.Simple(SynTypeDefnSimpleRepr.None(mName), mName), members, None, mName, trivia) }
SynTypeDefn($1, SynTypeDefnRepr.Simple(SynTypeDefnSimpleRepr.None(mName), mName), members, None, mWhole, trivia) }


/* The right-hand-side of a type definition */
Expand Down Expand Up @@ -1715,6 +1707,10 @@ tyconDefnRhsBlock:
let tcDefRepr, members = $2 nameRange (checkForMultipleAugmentations m ($4 @ optClassDefn) [])
tcDefRepr, mWith, members) }

| OBLOCKBEGIN oblockend
{ fun mName ->
SynTypeDefnRepr.Simple(SynTypeDefnSimpleRepr.None mName, mName), None, [] }

| tyconDefnRhs opt_classDefn
{ let m = rhs parseState 1
let mWith, optClassDefn = $2
Expand Down Expand Up @@ -1775,15 +1771,15 @@ tyconClassDefn:

/* The right-hand-side of a object type definition where the class/interface/struct kind has not been specified */
classDefnBlockKindUnspecified:
| OBLOCKBEGIN classDefnMembers recover
| OBLOCKBEGIN classDefnMembersAtLeastOne recover
{ if not $3 then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsUnexpectedEndOfFileTypeDefinition())
let mopt =
match $2 with
| _ :: _ -> Some((rhs parseState 1, $2) ||> unionRangeWithListBy (fun (d: SynMemberDefn) -> d.Range))
| _ -> None
false, $2, mopt }

| OBLOCKBEGIN classDefnMembers oblockend
| OBLOCKBEGIN classDefnMembersAtLeastOne oblockend
{ let mopt =
match $2 with
| _ :: _ -> Some((rhs parseState 1, $2) ||> unionRangeWithListBy (fun (d: SynMemberDefn) -> d.Range))
Expand Down
5 changes: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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: 0 additions & 5 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
Expand Up @@ -11,10 +11,12 @@ module TestCompilerWarningLevel =
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"warn_level0.fs"|])>]
let ``warn_level0_fs --warn:0`` compilation =
compilation
|> withLangVersionPreview
|> asExe
|> withOptions ["--warn:0"]
|> compileAndRun
|> shouldSucceed
|> withDiagnostics []

[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"warn_level1.fs"|])>]
let ``warn_level1_fs --warn:1 --warnaserror:52`` compilation =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
// #NoMT #CompilerOptions

[<NoComparison>]
/// Meh - Informational diagnostics "XML comment is not placed on a valid language element."
type A = int

let x = 10
// Normally a The result of this equality expression has type 'bool' and is implicitly discarded.
x = 20

let mul x y = x * y
// Normally a warning
[<TailCall>]
let rec fact n acc =
if n = 0
then acc
else (fact (n - 1) (mul n acc)) + 23

// Normally a 'Main module of program is empty: nothing will happen when it is run' warning
()
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ module TypeAbbreviations =
|> shouldFail
|> withDiagnostics [
(Error 10, Line 8, Col 1, Line 8, Col 5, "Incomplete structured construct at or before this point in type definition")
(Error 547, Line 6, Col 6, Line 6, Col 15, "A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'.")
]

//SOURCE=E_IncorrectRightSide_Keyword.fsx SCFLAGS="--test:ErrorRanges" # E_IncorrectRightSide_Keyword.fsx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ module ``Type definition missing equals`` =
type X | A | B
"""
FSharpDiagnosticSeverity.Error
3360
10
(2, 8, 2, 9)
"Unexpected token in type definition. Expected '=' after the type 'X'."
"Unexpected symbol '|' in type definition. Expected '=' or other token."
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,7 @@ FSharp.Compiler.CodeAnalysis.FSharpChecker: Void ClearCache(System.Collections.G
FSharp.Compiler.CodeAnalysis.FSharpChecker: Void ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateAll()
FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharp.Compiler.CodeAnalysis.FSharpProjectOptions, Microsoft.FSharp.Core.FSharpOption`1[System.String])
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPositionWithinTypeDefinition(FSharp.Compiler.Text.Position)
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsBindingALambdaAtPosition(FSharp.Compiler.Text.Position)
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPosContainedInApplication(FSharp.Compiler.Text.Position)
FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPositionContainedInACurriedParameter(FSharp.Compiler.Text.Position)
Expand Down
Loading

0 comments on commit ed74744

Please sign in to comment.