From d643cfb2f7d8fc9593caae87a46504637ee7242e Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Fri, 20 Sep 2024 22:07:55 +0100 Subject: [PATCH 01/14] Treat `{ 1..10 }` as sequence expression --- .../Expressions/CheckSequenceExpressions.fs | 43 ++++++++++++++++--- .../Language/SequenceExpressionTests.fs | 14 +++++- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs index 31be49131ab..6655d03c445 100644 --- a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs @@ -441,9 +441,32 @@ let TcSequenceExpression (cenv: TcFileState) env tpenv comp (overallTy: OverallT delayedExpr, tpenv let TcSequenceExpressionEntry (cenv: TcFileState) env (overallTy: OverallTy) tpenv (hasBuilder, comp) m = - match RewriteRangeExpr comp with - | Some replacementExpr -> TcExpr cenv overallTy env tpenv replacementExpr - | None -> + match comp with + | SynExpr.IndexRange _ -> + match RewriteRangeExpr comp with + | Some replacementExpr -> TcExpr cenv overallTy env tpenv replacementExpr + | None -> + let implicitYieldEnabled = + cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield + + let validateObjectSequenceOrRecordExpression = not implicitYieldEnabled + + match comp with + | SimpleSemicolonSequence cenv false _ when validateObjectSequenceOrRecordExpression -> + errorR (Error(FSComp.SR.tcInvalidObjectSequenceOrRecordExpression (), m)) + | _ -> () + + TcSequenceExpression cenv env tpenv comp overallTy m + + | SynExpr.Sequential _ when not hasBuilder && not cenv.g.compilingFSharpCore -> + let rec loopSynExpr synExpr = + match synExpr with + | SynExpr.Sequential(debugPointAtSequential, isTrueSeq, synExpr1, synExpr2, mWhole, trivia) -> + let synExpr1 = loopSynExpr synExpr1 + let synExpr2 = loopSynExpr synExpr2 + SynExpr.Sequential(debugPointAtSequential, isTrueSeq, synExpr1, synExpr2, mWhole, trivia) + | _ -> synExpr + let implicitYieldEnabled = cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield @@ -454,7 +477,17 @@ let TcSequenceExpressionEntry (cenv: TcFileState) env (overallTy: OverallTy) tpe errorR (Error(FSComp.SR.tcInvalidObjectSequenceOrRecordExpression (), m)) | _ -> () - if not hasBuilder && not cenv.g.compilingFSharpCore then - error (Error(FSComp.SR.tcInvalidSequenceExpressionSyntaxForm (), m)) + TcSequenceExpression cenv env tpenv (loopSynExpr comp) overallTy m + + | _ -> + let implicitYieldEnabled = + cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield + + let validateObjectSequenceOrRecordExpression = not implicitYieldEnabled + + match comp with + | SimpleSemicolonSequence cenv false _ when validateObjectSequenceOrRecordExpression -> + errorR (Error(FSComp.SR.tcInvalidObjectSequenceOrRecordExpression (), m)) + | _ -> () TcSequenceExpression cenv env tpenv comp overallTy m diff --git a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs index 982ae0c820b..04636c4dffc 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs @@ -442,4 +442,16 @@ let typedSeq = |> withErrorCode 30 |> withDiagnosticMessageMatches "Value restriction: The value 'typedSeq' has an inferred generic type" |> withDiagnosticMessageMatches "val typedSeq: '_a seq" - \ No newline at end of file + +[] +let ``Valid sequence expressions``() = + Fsx """ +{ 1;10 } +seq { 1;10 } +let x = { 1;10 } +let y = seq { 1;10 } + """ + |> ignoreWarnings + |> withLangVersion90 + |> typecheck + |> shouldSucceed \ No newline at end of file From 4d45b1ae7bc3c990e579ecd199c4e65e70c49ccc Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sat, 21 Sep 2024 18:44:52 +0100 Subject: [PATCH 02/14] deprecate { start..finish } and { start..step..finish } --- .../Expressions/CheckSequenceExpressions.fs | 54 ++--- src/Compiler/FSComp.txt | 5 +- src/Compiler/Facilities/LanguageFeatures.fs | 3 + src/Compiler/Facilities/LanguageFeatures.fsi | 1 + src/Compiler/xlf/FSComp.txt.cs.xlf | 9 +- src/Compiler/xlf/FSComp.txt.de.xlf | 9 +- src/Compiler/xlf/FSComp.txt.es.xlf | 9 +- src/Compiler/xlf/FSComp.txt.fr.xlf | 9 +- src/Compiler/xlf/FSComp.txt.it.xlf | 9 +- src/Compiler/xlf/FSComp.txt.ja.xlf | 9 +- src/Compiler/xlf/FSComp.txt.ko.xlf | 9 +- src/Compiler/xlf/FSComp.txt.pl.xlf | 9 +- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 9 +- src/Compiler/xlf/FSComp.txt.ru.xlf | 9 +- src/Compiler/xlf/FSComp.txt.tr.xlf | 9 +- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 9 +- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 9 +- .../Language/SequenceExpressionTests.fs | 202 +++++++++++++++++- 18 files changed, 310 insertions(+), 72 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs index 6655d03c445..d3e92e8b71d 100644 --- a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs @@ -441,32 +441,20 @@ let TcSequenceExpression (cenv: TcFileState) env tpenv comp (overallTy: OverallT delayedExpr, tpenv let TcSequenceExpressionEntry (cenv: TcFileState) env (overallTy: OverallTy) tpenv (hasBuilder, comp) m = - match comp with - | SynExpr.IndexRange _ -> - match RewriteRangeExpr comp with - | Some replacementExpr -> TcExpr cenv overallTy env tpenv replacementExpr - | None -> - let implicitYieldEnabled = - cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield - - let validateObjectSequenceOrRecordExpression = not implicitYieldEnabled - - match comp with - | SimpleSemicolonSequence cenv false _ when validateObjectSequenceOrRecordExpression -> - errorR (Error(FSComp.SR.tcInvalidObjectSequenceOrRecordExpression (), m)) - | _ -> () - - TcSequenceExpression cenv env tpenv comp overallTy m - - | SynExpr.Sequential _ when not hasBuilder && not cenv.g.compilingFSharpCore -> - let rec loopSynExpr synExpr = - match synExpr with - | SynExpr.Sequential(debugPointAtSequential, isTrueSeq, synExpr1, synExpr2, mWhole, trivia) -> - let synExpr1 = loopSynExpr synExpr1 - let synExpr2 = loopSynExpr synExpr2 - SynExpr.Sequential(debugPointAtSequential, isTrueSeq, synExpr1, synExpr2, mWhole, trivia) - | _ -> synExpr - + match RewriteRangeExpr comp with + | Some replacementExpr -> + let deprecatedPlacesWhereSeqCanBeOmitted = + cenv.g.langVersion.SupportsFeature LanguageFeature.DeprecatePlacesWhereSeqCanBeOmitted + + if + deprecatedPlacesWhereSeqCanBeOmitted + && not hasBuilder + && not cenv.g.compilingFSharpCore + then + warning (Error(FSComp.SR.tcInvalidSequenceExpressionSyntaxForm (), m)) + + TcExpr cenv overallTy env tpenv replacementExpr + | None -> let implicitYieldEnabled = cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield @@ -477,17 +465,7 @@ let TcSequenceExpressionEntry (cenv: TcFileState) env (overallTy: OverallTy) tpe errorR (Error(FSComp.SR.tcInvalidObjectSequenceOrRecordExpression (), m)) | _ -> () - TcSequenceExpression cenv env tpenv (loopSynExpr comp) overallTy m - - | _ -> - let implicitYieldEnabled = - cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield - - let validateObjectSequenceOrRecordExpression = not implicitYieldEnabled - - match comp with - | SimpleSemicolonSequence cenv false _ when validateObjectSequenceOrRecordExpression -> - errorR (Error(FSComp.SR.tcInvalidObjectSequenceOrRecordExpression (), m)) - | _ -> () + if not hasBuilder && not cenv.g.compilingFSharpCore then + errorR (Error(FSComp.SR.tcInvalidSequenceExpressionSyntaxForm (), m)) TcSequenceExpression cenv env tpenv comp overallTy m diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index b5a50afc7c0..2742af0437f 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -591,7 +591,7 @@ tcCouldNotFindIDisposable,"Couldn't find Dispose on IDisposable, or it was overl 737,tcExpressionRequiresSequence,"This expression form may only be used in sequence and computation expressions" 738,tcInvalidObjectExpressionSyntaxForm,"Invalid object expression. Objects without overrides or interfaces should use the expression form 'new Type(args)' without braces." 739,tcInvalidObjectSequenceOrRecordExpression,"Invalid object, sequence or record expression" -740,tcInvalidSequenceExpressionSyntaxForm,"Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}'" +740,tcInvalidSequenceExpressionSyntaxForm,"Sequence expressions should be of the form 'seq {{ ... }}'" tcExpressionWithIfRequiresParenthesis,"This list or array expression includes an element of the form 'if ... then ... else'. Parenthesize this expression to indicate it is an individual element of the list or array, to disambiguate this from a list generated using a sequence expression" 741,tcUnableToParseFormatString,"Unable to parse format string '%s'" 742,tcListLiteralMaxSize,"This list expression exceeds the maximum size for list literals. Use an array for larger literals and call Array.ToList." @@ -1783,4 +1783,5 @@ featureEmptyBodiedComputationExpressions,"Support for computation expressions wi featureAllowAccessModifiersToAutoPropertiesGettersAndSetters,"Allow access modifiers to auto properties getters and setters" 3871,tcAccessModifiersNotAllowedInSRTPConstraint,"Access modifiers cannot be applied to an SRTP constraint." featureAllowObjectExpressionWithoutOverrides,"Allow object expressions without overrides" -3872,tcPartialActivePattern,"Multi-case partial active patterns are not supported. Consider using a single-case partial active pattern or a full active pattern." \ No newline at end of file +3872,tcPartialActivePattern,"Multi-case partial active patterns are not supported. Consider using a single-case partial active pattern or a full active pattern." +featureDeprecatePlacesWhereSeqCanBeOmitted,"Deprecate places where 'seq' can be omitted" \ No newline at end of file diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 5c311237594..3488a3399e1 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -94,6 +94,7 @@ type LanguageFeature = | ParsedHashDirectiveArgumentNonQuotes | EmptyBodiedComputationExpressions | AllowObjectExpressionWithoutOverrides + | DeprecatePlacesWhereSeqCanBeOmitted /// LanguageVersion management type LanguageVersion(versionText) = @@ -219,6 +220,7 @@ type LanguageVersion(versionText) = LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, previewVersion LanguageFeature.AllowObjectExpressionWithoutOverrides, previewVersion + LanguageFeature.DeprecatePlacesWhereSeqCanBeOmitted, previewVersion ] static let defaultLanguageVersion = LanguageVersion("default") @@ -375,6 +377,7 @@ type LanguageVersion(versionText) = | LanguageFeature.ParsedHashDirectiveArgumentNonQuotes -> FSComp.SR.featureParsedHashDirectiveArgumentNonString () | LanguageFeature.EmptyBodiedComputationExpressions -> FSComp.SR.featureEmptyBodiedComputationExpressions () | LanguageFeature.AllowObjectExpressionWithoutOverrides -> FSComp.SR.featureAllowObjectExpressionWithoutOverrides () + | LanguageFeature.DeprecatePlacesWhereSeqCanBeOmitted -> FSComp.SR.featureDeprecatePlacesWhereSeqCanBeOmitted () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index 7408300b943..6396f7b72c0 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -85,6 +85,7 @@ type LanguageFeature = | ParsedHashDirectiveArgumentNonQuotes | EmptyBodiedComputationExpressions | AllowObjectExpressionWithoutOverrides + | DeprecatePlacesWhereSeqCanBeOmitted /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 2b1a9483def..3cbd52e47ee 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -322,6 +322,11 @@ opravit překlad názvů typů delegátů, viz https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding vzor discard ve vazbě použití @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Neplatný výraz záznamu, pořadí nebo výpočtu. Výrazy pořadí by měly mít notaci seq {{ ... }}. + Sequence expressions should be of the form 'seq {{ ... }}' + Neplatný výraz záznamu, pořadí nebo výpočtu. Výrazy pořadí by měly mít notaci seq {{ ... }}. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index a1b2532e4db..a5d23b6e395 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -322,6 +322,11 @@ Informationen zur Problembehebung bezüglich der Auflösung von Delegattypnamen finden Sie unter https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding Das Verwerfen des verwendeten Musters ist verbindlich. @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Ungültiger Datensatz-, Sequenz- oder Berechnungsausdruck. Sequenzausdrücke müssen das Format "seq {{ ... }}" besitzen. + Sequence expressions should be of the form 'seq {{ ... }}' + Ungültiger Datensatz-, Sequenz- oder Berechnungsausdruck. Sequenzausdrücke müssen das Format "seq {{ ... }}" besitzen. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index dd9cbb7fec6..2afe39f5603 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -322,6 +322,11 @@ corrección para la resolución de nombres de tipo de delegado, consulte https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding descartar enlace de patrón en uso @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Expresión de registro, secuencia o cómputo no válida. Las expresiones de secuencia deben tener el formato 'seq {{ ... }}'. + Sequence expressions should be of the form 'seq {{ ... }}' + Expresión de registro, secuencia o cómputo no válida. Las expresiones de secuencia deben tener el formato 'seq {{ ... }}'. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 2cc92e5f4d5..e596ed29a75 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -322,6 +322,11 @@ corriger pour résoudre les noms de types délégués, voir https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding annuler le modèle dans la liaison d’utilisation @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Expression d'enregistrement, de séquence ou de calcul non valide. Les expressions de séquence doivent avoir le format 'seq {{ ... }}' + Sequence expressions should be of the form 'seq {{ ... }}' + Expression d'enregistrement, de séquence ou de calcul non valide. Les expressions de séquence doivent avoir le format 'seq {{ ... }}' diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 5b5793c4841..1ac4d6cdb42 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -322,6 +322,11 @@ correggere la risoluzione dei nomi dei tipi delegati, vedere https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding rimuovi criterio nell'utilizzo dell'associazione @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Espressione di calcolo, sequenza o record non valida. Il formato delle espressioni sequenza deve essere 'seq {{ ... }}' + Sequence expressions should be of the form 'seq {{ ... }}' + Espressione di calcolo, sequenza o record non valida. Il formato delle espressioni sequenza deve essere 'seq {{ ... }}' diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index d30efc74724..a42fe7d8286 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -322,6 +322,11 @@ デリゲート型名の解決を修正するには、https://github.com/dotnet/fsharp/issues/10228 を参照してください + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding 使用バインドでパターンを破棄する @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - 無効なレコード、シーケンス式、またはコンピュテーション式です。シーケンス式は 'seq {{ ... }}' という形式にしてください。 + Sequence expressions should be of the form 'seq {{ ... }}' + 無効なレコード、シーケンス式、またはコンピュテーション式です。シーケンス式は 'seq {{ ... }}' という形式にしてください。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index c9359c56807..d8626088a97 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -322,6 +322,11 @@ 대리자 형식 이름의 해결 방법을 수정합니다. https://github.com/dotnet/fsharp/issues/10228 참조하세요. + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding 사용 중인 패턴 바인딩 무시 @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - 레코드, 시퀀스 또는 계산 식이 잘못되었습니다. 시퀀스 식의 형식은 'seq {{ ... }}'여야 합니다. + Sequence expressions should be of the form 'seq {{ ... }}' + 레코드, 시퀀스 또는 계산 식이 잘못되었습니다. 시퀀스 식의 형식은 'seq {{ ... }}'여야 합니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 933379b9f7b..f1b1b1fc426 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -322,6 +322,11 @@ naprawa rozpoznawania nazw typów delegatów, sprawdź stronę https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding odrzuć wzorzec w powiązaniu użycia @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Nieprawidłowe wyrażenie rekordu, sekwencji lub obliczenia. Wyrażenia sekwencji powinny mieć postać „seq {{ ... }}” + Sequence expressions should be of the form 'seq {{ ... }}' + Nieprawidłowe wyrażenie rekordu, sekwencji lub obliczenia. Wyrażenia sekwencji powinny mieć postać „seq {{ ... }}” diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index e6480e13025..ca7bdaa1427 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -322,6 +322,11 @@ corrigir para resolução de nomes de tipos delegados, consulte https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding descartar o padrão em uso de associação @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Expressão de registro, sequência ou computação inválida. Expressões de sequência devem estar na forma 'seq {{ ... }}' + Sequence expressions should be of the form 'seq {{ ... }}' + Expressão de registro, sequência ou computação inválida. Expressões de sequência devem estar na forma 'seq {{ ... }}' diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 61c03885917..3b75c3d71a9 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -322,6 +322,11 @@ исправить разрешение имен типов делегатов, см. https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding шаблон отмены в привязке использования @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Недопустимая запись, выражение последовательности или вычислительное выражение. Выражения последовательностей должны иметь форму "seq {{ ... }}' + Sequence expressions should be of the form 'seq {{ ... }}' + Недопустимая запись, выражение последовательности или вычислительное выражение. Выражения последовательностей должны иметь форму "seq {{ ... }}' diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 09c113ee3f1..ae649852d4d 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -322,6 +322,11 @@ temsilci türü adlarının çözümlenmesiyle ilgili sorunun çözümü için bkz. https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding kullanım bağlamasında deseni at @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - Geçersiz kayıt, dizi veya hesaplama ifadesi. Dizi ifadeleri 'seq {{ ... }}' biçiminde olmalıdır + Sequence expressions should be of the form 'seq {{ ... }}' + Geçersiz kayıt, dizi veya hesaplama ifadesi. Dizi ifadeleri 'seq {{ ... }}' biçiminde olmalıdır diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index d9573b5bed2..6706ef41a76 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -322,6 +322,11 @@ 修复了委托类型名称的解析,请参阅 https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding 放弃使用绑定模式 @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - 记录、序列或计算表达式无效。序列表达式的格式应为“seq {{ ... }}” + Sequence expressions should be of the form 'seq {{ ... }}' + 记录、序列或计算表达式无效。序列表达式的格式应为“seq {{ ... }}” diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 1a6c3de6ccf..97e4901139d 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -322,6 +322,11 @@ 修正委派類型名稱的解析,請參閱 https://github.com/dotnet/fsharp/issues/10228 + + Deprecate places where 'seq' can be omitted + Deprecate places where 'seq' can be omitted + + discard pattern in use binding 捨棄使用繫結中的模式 @@ -4523,8 +4528,8 @@ - Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' - 無效的記錄、循序項或計算運算式。循序項運算式應該是 'seq {{ ... }}' 形式。 + Sequence expressions should be of the form 'seq {{ ... }}' + 無效的記錄、循序項或計算運算式。循序項運算式應該是 'seq {{ ... }}' 形式。 diff --git a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs index 04636c4dffc..5b4b7a7985b 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs @@ -444,14 +444,204 @@ let typedSeq = |> withDiagnosticMessageMatches "val typedSeq: '_a seq" [] -let ``Valid sequence expressions``() = +let ``Sequence(SynExpr.Sequential) expressions should be of the form 'seq { ... } lang version 9``() = Fsx """ { 1;10 } -seq { 1;10 } -let x = { 1;10 } -let y = seq { 1;10 } +[| { 1;10 } |] +let a = { 1;10 } +let b = [| { 1;10 } |] +let c = [ { 1;10 } ] """ - |> ignoreWarnings + |> withOptions [ "--nowarn:0020" ] |> withLangVersion90 |> typecheck - |> shouldSucceed \ No newline at end of file + |> shouldFail + |> withDiagnostics [ + (Error 740, Line 2, Col 1, Line 2, Col 9, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 3, Col 4, Line 3, Col 12, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 4, Col 9, Line 4, Col 17, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 5, Col 12, Line 5, Col 20, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 6, Col 11, Line 6, Col 19, "Sequence expressions should be of the form 'seq { ... }'") + ] + +[] +let ``Sequence(SynExpr.Sequential) expressions should be of the form 'seq { ... } lang version preview``() = + Fsx """ +{ 1;10 } +[| { 1;10 } |] +let a = { 1;10 } +let b = [| { 1;10 } |] +let c = [ { 1;10 } ] + """ + |> withOptions [ "--nowarn:0020" ] + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 740, Line 2, Col 1, Line 2, Col 9, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 3, Col 4, Line 3, Col 12, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 4, Col 9, Line 4, Col 17, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 5, Col 12, Line 5, Col 20, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 6, Col 11, Line 6, Col 19, "Sequence expressions should be of the form 'seq { ... }'") + ] + +[] +let ``Sequence(SynExpr.IndexRange) expressions should be of the form 'seq { ... } lang version 9``() = + Fsx """ +{ 1..10 } + +{ 1..5..10 } + +[| { 1..10 } |] + +[| { 1..5..10 } |] + +let a = { 1..10 } + +let a3 = { 1..10..20 } + +let b = [| { 1..10 } |] + +let b3 = [| { 1..10..20 } |] + +let c = [ { 1..10 } ] + +[| { 1..10 } |] + +[| yield { 1..10 } |] + +[ { 1..10 } ] + +[ { 1..10..10 } ] + +[ yield { 1..10 } ] + +[ yield { 1..10..20 } ] + +ResizeArray({ 1..10 }) + +ResizeArray({ 1..10..20 }) + +let fw start finish = [ for x in { start..finish } -> x ] + +let fe start finish = [| for x in { start..finish } -> x |] + +for x in { 1..10 } do () + +for x in { 1..5..10 } do () + +let f = Seq.head + +let a2 = f { 1..6 } + +let a23 = f { 1..6..10 } + +let b2 = set { 1..6 } + +let f10 start finish = for x in { start..finish } do ignore (float x ** float x) + +let (..) _ _ = "lol" + +let lol1 = { 1..10 } + +{ 1..5..10 } + """ + |> withOptions [ "--nowarn:0020" ] + |> withLangVersion90 + |> typecheck + |> shouldSucceed + +[] +let ``Sequence(SynExpr.IndexRange) expressions should be of the form 'seq { ... }``() = + Fsx """ +{ 1..10 } + +{ 1..5..10 } + +[| { 1..10 } |] + +[| { 1..5..10 } |] + +let a = { 1..10 } + +let a3 = { 1..10..20 } + +let b = [| { 1..10 } |] + +let b3 = [| { 1..10..20 } |] + +let c = [ { 1..10 } ] + +[| { 1..10 } |] + +[| yield { 1..10 } |] + +[ { 1..10 } ] + +[ { 1..10..10 } ] + +[ yield { 1..10 } ] + +[ yield { 1..10..20 } ] + +ResizeArray({ 1..10 }) + +ResizeArray({ 1..10..20 }) + +let fw start finish = [ for x in { start..finish } -> x ] + +let fe start finish = [| for x in { start..finish } -> x |] + +for x in { 1..10 } do () + +for x in { 1..5..10 } do () + +let f = Seq.head + +let a2 = f { 1..6 } + +let a23 = f { 1..6..10 } + +let b2 = set { 1..6 } + +let f10 start finish = for x in { start..finish } do ignore (float x ** float x) + +let (..) _ _ = "lol" + +let lol1 = { 1..10 } + +{ 1..5..10 } + """ + |> withOptions [ "--nowarn:0020" ] + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 740, Line 2, Col 1, Line 2, Col 10, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 4, Col 1, Line 4, Col 13, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 6, Col 4, Line 6, Col 13, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 8, Col 4, Line 8, Col 16, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 10, Col 9, Line 10, Col 18, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 12, Col 10, Line 12, Col 23, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 14, Col 12, Line 14, Col 21, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 16, Col 13, Line 16, Col 26, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 18, Col 11, Line 18, Col 20, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 20, Col 4, Line 20, Col 13, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 22, Col 10, Line 22, Col 19, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 24, Col 3, Line 24, Col 12, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 26, Col 3, Line 26, Col 16, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 28, Col 9, Line 28, Col 18, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 30, Col 9, Line 30, Col 22, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 32, Col 13, Line 32, Col 22, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 34, Col 13, Line 34, Col 26, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 36, Col 34, Line 36, Col 51, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 38, Col 35, Line 38, Col 52, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 40, Col 10, Line 40, Col 19, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 42, Col 10, Line 42, Col 22, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 46, Col 12, Line 46, Col 20, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 48, Col 13, Line 48, Col 25, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 50, Col 14, Line 50, Col 22, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 52, Col 33, Line 52, Col 50, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 56, Col 12, Line 56, Col 21, "Sequence expressions should be of the form 'seq { ... }'"); + (Warning 740, Line 58, Col 1, Line 58, Col 13, "Sequence expressions should be of the form 'seq { ... }'") + ] \ No newline at end of file From 47b4ef0d684547af0376a52fc7b2e5726efd0fc3 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 22 Sep 2024 10:31:41 +0100 Subject: [PATCH 03/14] fix build part1 --- .../PatternMatchCompilationTests.fs | 6 +- .../ArrayModule.fs | 4 +- .../ArrayModule2.fs | 2 +- .../ListModule.fs | 4 +- .../ListModule2.fs | 2 +- .../ObsoleteSeqFunctions.fs | 6 +- .../Microsoft.FSharp.Collections/SeqModule.fs | 34 +++---- .../SeqModule2.fs | 54 +++++------ .../FSharp.Core/PrimTypes.fs | 92 +++++++++---------- .../TestFrameworkHelpers.fs | 2 +- 10 files changed, 103 insertions(+), 103 deletions(-) diff --git a/tests/FSharp.Compiler.Service.Tests/PatternMatchCompilationTests.fs b/tests/FSharp.Compiler.Service.Tests/PatternMatchCompilationTests.fs index 4ae43434099..e22c58e8a3a 100644 --- a/tests/FSharp.Compiler.Service.Tests/PatternMatchCompilationTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/PatternMatchCompilationTests.fs @@ -455,7 +455,7 @@ let r as _ = 10 let s as Id0 = 11 let t as (u) = 12 let v as struct(w, x) = 13, 14 -let y as z : int = 15{set { 'a'..'x' } - set [ 'p'; 'v' ] |> Set.map (sprintf " + %c") |> System.String.Concat} +let y as z : int = 15{set (seq { 'a'..'x' }) - set [ 'p'; 'v' ] |> Set.map (sprintf " + %c") |> System.String.Concat} Some p |> eq Some v |> eq () @@ -590,7 +590,7 @@ let _ as r = 10 let Id0 as s = 11 let (t) as u = 12 let struct(w, v) as x = 13, 14 -let (y : int) as z = 15{set { 'a'..'v' } - set [ 'h'; 'q' ] |> Set.map (sprintf " + %c") |> System.String.Concat} +let (y : int) as z = 15{set (seq { 'a'..'v' }) - set [ 'h'; 'q' ] |> Set.map (sprintf " + %c") |> System.String.Concat} Some h |> eq Some q |> eq Some x |> eq @@ -917,7 +917,7 @@ let :? z as [] let ``As 16 - syntactical precedence matrix testing left with type tests - total patterns`` () = - let validSet = set { 'a'..'x' } - set [ 'p'; 'q' ] |> Set.map string + let validSet = set (seq { 'a'..'x' }) - set [ 'p'; 'q' ] |> Set.map string let _, checkResults = getParseAndCheckResults70 $""" let eq<'T> (x:'T option) = () // FS-1093-safe type assert function let (|Id0|) = ignore diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs index c2b0d240372..662a729e28f 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs @@ -259,8 +259,8 @@ type ArrayModule() = [] member _.Except() = // integer array - let intArr1 = [| yield! {1..100} - yield! {1..100} |] + let intArr1 = [| yield! seq {1..100} + yield! seq {1..100} |] let intArr2 = [| 1 .. 10 |] let expectedIntArr = [| 11 .. 100 |] diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs index ec30e724bbb..5c5afc3c234 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs @@ -372,7 +372,7 @@ type ArrayModule2() = [] member this.Of_Seq() = // integer array - let resultInt = Array.ofSeq {1..10} + let resultInt = Array.ofSeq (seq {1..10}) if resultInt <> [|1..10|] then Assert.Fail() // string array diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule.fs index 9f3ae062d02..8b0fcf507e5 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule.fs @@ -346,8 +346,8 @@ type ListModule() = [] member _.Except() = // integer list - let intList1 = [ yield! {1..100} - yield! {1..100} ] + let intList1 = [ yield! seq {1..100} + yield! seq {1..100} ] let intList2 = [1..10] let expectedIntList = [11..100] diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs index 328574bdac0..3a27d4e7d2a 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs @@ -367,7 +367,7 @@ type ListModule02() = [] member this.Of_Seq() = // integer List - let resultInt = List.ofSeq {1..10} + let resultInt = List.ofSeq (seq {1..10}) Assert.AreEqual([1..10], resultInt) // string List diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ObsoleteSeqFunctions.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ObsoleteSeqFunctions.fs index 3b8727fc538..67c5aeba747 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ObsoleteSeqFunctions.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ObsoleteSeqFunctions.fs @@ -15,14 +15,14 @@ type ObsoleteSeqFunctions() = // Negative index for i = -1 downto -10 do - CheckThrowsArgumentException (fun () -> Seq.nth i { 10 .. 20 } |> ignore) + CheckThrowsArgumentException (fun () -> Seq.nth i (seq { 10 .. 20 }) |> ignore) // Out of range for i = 11 to 20 do - CheckThrowsArgumentException (fun () -> Seq.nth i { 10 .. 20 } |> ignore) + CheckThrowsArgumentException (fun () -> Seq.nth i (seq { 10 .. 20 }) |> ignore) // integer Seq - let resultInt = Seq.nth 3 { 10..20 } + let resultInt = Seq.nth 3 (seq { 10..20 }) Assert.AreEqual(13, resultInt) // string Seq diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs index de6f66dd7ec..f2f88933506 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs @@ -39,8 +39,8 @@ type SeqModule() = // empty Seq VerifySeqsEqual Seq.empty <| Seq.allPairs Seq.empty Seq.empty - VerifySeqsEqual Seq.empty <| Seq.allPairs { 1..7 } Seq.empty - VerifySeqsEqual Seq.empty <| Seq.allPairs Seq.empty { 1..7 } + VerifySeqsEqual Seq.empty <| Seq.allPairs (seq { 1..7 }) Seq.empty + VerifySeqsEqual Seq.empty <| Seq.allPairs Seq.empty (seq { 1..7 }) // null Seq CheckThrowsArgumentNullException(fun() -> Seq.allPairs null null |> ignore) @@ -349,9 +349,9 @@ type SeqModule() = |> Seq.iter ((<||) VerifySeqsEqual) // int Seq - verify [[1..4];[5..8]] <| Seq.chunkBySize 4 {1..8} - verify [[1..4];[5..8];[9..10]] <| Seq.chunkBySize 4 {1..10} - verify [[1]; [2]; [3]; [4]] <| Seq.chunkBySize 1 {1..4} + verify [[1..4];[5..8]] <| Seq.chunkBySize 4 (seq {1..8}) + verify [[1..4];[5..8];[9..10]] <| Seq.chunkBySize 4 (seq {1..10}) + verify [[1]; [2]; [3]; [4]] <| Seq.chunkBySize 1 (seq {1..4}) Seq.chunkBySize 2 (Seq.initInfinite id) |> Seq.take 3 @@ -372,8 +372,8 @@ type SeqModule() = CheckThrowsArgumentNullException (fun () -> Seq.chunkBySize 3 nullSeq |> ignore) // invalidArg - CheckThrowsArgumentException (fun () -> Seq.chunkBySize 0 {1..10} |> ignore) - CheckThrowsArgumentException (fun () -> Seq.chunkBySize -1 {1..10} |> ignore) + CheckThrowsArgumentException (fun () -> Seq.chunkBySize 0 (seq {1..10}) |> ignore) + CheckThrowsArgumentException (fun () -> Seq.chunkBySize -1 (seq {1..10}) |> ignore) () @@ -385,12 +385,12 @@ type SeqModule() = |> Seq.iter ((<||) VerifySeqsEqual) // int Seq - Seq.splitInto 3 {1..10} |> verify (seq [ {1..4}; {5..7}; {8..10} ]) - Seq.splitInto 3 {1..11} |> verify (seq [ {1..4}; {5..8}; {9..11} ]) - Seq.splitInto 3 {1..12} |> verify (seq [ {1..4}; {5..8}; {9..12} ]) + Seq.splitInto 3 (seq {1..10}) |> verify (seq [ seq {1..4}; seq {5..7}; seq {8..10} ]) + Seq.splitInto 3 (seq {1..11}) |> verify (seq [ seq {1..4}; seq {5..8}; seq {9..11} ]) + Seq.splitInto 3 (seq {1..12}) |> verify (seq [ seq {1..4}; seq {5..8}; seq {9..12} ]) - Seq.splitInto 4 {1..5} |> verify (seq [ [1..2]; [3]; [4]; [5] ]) - Seq.splitInto 20 {1..4} |> verify (seq [ [1]; [2]; [3]; [4] ]) + Seq.splitInto 4 (seq {1..5}) |> verify (seq [ [1..2]; [3]; [4]; [5] ]) + Seq.splitInto 20 (seq {1..4}) |> verify (seq [ [1]; [2]; [3]; [4] ]) // string Seq Seq.splitInto 3 ["a";"b";"c";"d";"e"] |> verify ([ ["a"; "b"]; ["c";"d"]; ["e"] ]) @@ -586,10 +586,10 @@ type SeqModule() = [] member _.Except() = // integer Seq - let intSeq1 = seq { yield! {1..100} - yield! {1..100} } - let intSeq2 = {1..10} - let expectedIntSeq = {11..100} + let intSeq1 = seq { yield! seq {1..100} + yield! seq {1..100} } + let intSeq2 = seq {1..10} + let expectedIntSeq = seq {11..100} VerifySeqsEqual expectedIntSeq <| Seq.except intSeq2 intSeq1 @@ -609,7 +609,7 @@ type SeqModule() = // empty Seq let emptyIntSeq = Seq.empty - VerifySeqsEqual {1..100} <| Seq.except emptyIntSeq intSeq1 + VerifySeqsEqual (seq {1..100}) <| Seq.except emptyIntSeq intSeq1 VerifySeqsEqual emptyIntSeq <| Seq.except intSeq1 emptyIntSeq VerifySeqsEqual emptyIntSeq <| Seq.except emptyIntSeq emptyIntSeq VerifySeqsEqual emptyIntSeq <| Seq.except intSeq1 intSeq1 diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs index 8412b999b5d..db3b8a3adcc 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs @@ -479,7 +479,7 @@ type SeqModule2() = member _.Length() = // integer seq - let resultInt = Seq.length {1..8} + let resultInt = Seq.length (seq {1..8}) if resultInt <> 8 then Assert.Fail() // string Seq @@ -505,7 +505,7 @@ type SeqModule2() = | _ when x % 2 = 0 -> 10*x | _ -> x - let resultInt = Seq.map funcInt { 1..10 } + let resultInt = Seq.map funcInt (seq { 1..10 }) let expectedint = seq [1;20;3;40;5;60;7;80;9;100] VerifySeqsEqual expectedint resultInt @@ -531,7 +531,7 @@ type SeqModule2() = member _.Map2() = // integer Seq let funcInt x y = x+y - let resultInt = Seq.map2 funcInt { 1..10 } {2..2..20} + let resultInt = Seq.map2 funcInt (seq { 1..10 }) (seq {2..2..20}) let expectedint = seq [3;6;9;12;15;18;21;24;27;30] VerifySeqsEqual expectedint resultInt @@ -558,16 +558,16 @@ type SeqModule2() = member _.Map3() = // Integer seq let funcInt a b c = (a + b) * c - let resultInt = Seq.map3 funcInt { 1..8 } { 2..9 } { 3..10 } + let resultInt = Seq.map3 funcInt (seq { 1..8 }) (seq { 2..9 }) (seq { 3..10 }) let expectedInt = seq [9; 20; 35; 54; 77; 104; 135; 170] VerifySeqsEqual expectedInt resultInt // First seq is shorter - VerifySeqsEqual (seq [9; 20]) (Seq.map3 funcInt { 1..2 } { 2..9 } { 3..10 }) + VerifySeqsEqual (seq [9; 20]) (Seq.map3 funcInt (seq { 1..2 }) (seq { 2..9 }) (seq { 3..10 })) // Second seq is shorter - VerifySeqsEqual (seq [9; 20; 35]) (Seq.map3 funcInt { 1..8 } { 2..4 } { 3..10 }) + VerifySeqsEqual (seq [9; 20; 35]) (Seq.map3 funcInt (seq { 1..8 }) (seq { 2..4 }) (seq { 3..10 })) // Third seq is shorter - VerifySeqsEqual (seq [9; 20; 35; 54]) (Seq.map3 funcInt { 1..8 } { 2..6 } { 3..6 }) + VerifySeqsEqual (seq [9; 20; 35; 54]) (Seq.map3 funcInt (seq { 1..8 }) (seq { 2..6 }) (seq { 3..6 })) // String seq let funcStr a b c = a + b + c @@ -812,7 +812,7 @@ type SeqModule2() = member _.Collect() = // integer Seq let funcInt x = seq [x+1] - let resultInt = Seq.collect funcInt { 1..10 } + let resultInt = Seq.collect funcInt (seq { 1..10 }) let expectedint = seq {2..11} @@ -843,7 +843,7 @@ type SeqModule2() = // integer Seq let funcInt x y = x+y - let resultInt = Seq.mapi funcInt { 10..2..20 } + let resultInt = Seq.mapi funcInt (seq { 10..2..20 }) let expectedint = seq [10;13;16;19;22;25] VerifySeqsEqual expectedint resultInt @@ -871,7 +871,7 @@ type SeqModule2() = member _.Mapi2() = // integer Seq let funcInt x y z = x+y+z - let resultInt = Seq.mapi2 funcInt { 1..10 } {2..2..20} + let resultInt = Seq.mapi2 funcInt (seq { 1..10 }) (seq {2..2..20}) let expectedint = seq [3;7;11;15;19;23;27;31;35;39] VerifySeqsEqual expectedint resultInt @@ -907,7 +907,7 @@ type SeqModule2() = member _.Indexed() = // integer Seq - let resultInt = Seq.indexed { 10..2..20 } + let resultInt = Seq.indexed (seq { 10..2..20 }) let expectedint = seq [(0,10);(1,12);(2,14);(3,16);(4,18);(5,20)] VerifySeqsEqual expectedint resultInt @@ -931,7 +931,7 @@ type SeqModule2() = [] member _.Max() = // integer Seq - let resultInt = Seq.max { 10..20 } + let resultInt = Seq.max (seq { 10..20 }) Assert.AreEqual(20,resultInt) @@ -954,7 +954,7 @@ type SeqModule2() = // integer Seq let funcInt x = x % 8 - let resultInt = Seq.maxBy funcInt { 2..2..20 } + let resultInt = Seq.maxBy funcInt (seq { 2..2..20 }) Assert.AreEqual(6,resultInt) // string Seq @@ -976,7 +976,7 @@ type SeqModule2() = // integer Seq let funcInt x = x % 8 - let resultInt = Seq.minBy funcInt { 2..2..20 } + let resultInt = Seq.minBy funcInt (seq { 2..2..20 }) Assert.AreEqual(8,resultInt) // string Seq @@ -998,7 +998,7 @@ type SeqModule2() = member _.Min() = // integer Seq - let resultInt = Seq.min { 10..20 } + let resultInt = Seq.min (seq { 10..20 }) Assert.AreEqual(10,resultInt) // string Seq @@ -1017,7 +1017,7 @@ type SeqModule2() = [] member _.Item() = // integer Seq - let resultInt = Seq.item 3 { 10..20 } + let resultInt = Seq.item 3 (seq { 10..20 }) Assert.AreEqual(13, resultInt) // string Seq @@ -1033,11 +1033,11 @@ type SeqModule2() = // Negative index for i = -1 downto -10 do - CheckThrowsArgumentException (fun () -> Seq.item i { 10 .. 20 } |> ignore) + CheckThrowsArgumentException (fun () -> Seq.item i (seq { 10 .. 20 }) |> ignore) // Out of range for i = 11 to 20 do - CheckThrowsArgumentException (fun () -> Seq.item i { 10 .. 20 } |> ignore) + CheckThrowsArgumentException (fun () -> Seq.item i (seq { 10 .. 20 }) |> ignore) [] member _.``item should fail with correct number of missing elements``() = @@ -1057,7 +1057,7 @@ type SeqModule2() = member _.Of_Array() = // integer Seq let resultInt = Seq.ofArray [|1..10|] - let expectedInt = {1..10} + let expectedInt = seq {1..10} VerifySeqsEqual expectedInt resultInt @@ -1076,7 +1076,7 @@ type SeqModule2() = member _.Of_List() = // integer Seq let resultInt = Seq.ofList [1..10] - let expectedInt = {1..10} + let expectedInt = seq {1..10} VerifySeqsEqual expectedInt resultInt @@ -1095,7 +1095,7 @@ type SeqModule2() = [] member _.Pairwise() = // integer Seq - let resultInt = Seq.pairwise {1..3} + let resultInt = Seq.pairwise (seq {1..3}) let expectedInt = seq [1,2;2,3] @@ -1182,7 +1182,7 @@ type SeqModule2() = member _.Scan() = // integer Seq let funcInt x y = x+y - let resultInt = Seq.scan funcInt 9 {1..10} + let resultInt = Seq.scan funcInt 9 (seq {1..10}) let expectedInt = seq [9;10;12;15;19;24;30;37;45;54;64] VerifySeqsEqual expectedInt resultInt @@ -1207,7 +1207,7 @@ type SeqModule2() = member _.ScanBack() = // integer Seq let funcInt x y = x+y - let resultInt = Seq.scanBack funcInt { 1..10 } 9 + let resultInt = Seq.scanBack funcInt (seq { 1..10 }) 9 let expectedInt = seq [64;63;61;58;54;49;43;36;28;19;9] VerifySeqsEqual expectedInt resultInt @@ -1313,7 +1313,7 @@ type SeqModule2() = // integer Seq let resultInt = Seq.sort (seq [1;3;2;4;6;5;7]) - let expectedInt = {1..7} + let expectedInt = seq {1..7} VerifySeqsEqual expectedInt resultInt // string Seq @@ -1960,7 +1960,7 @@ type SeqModule2() = [] member _.tryItem() = // integer Seq - let resultInt = Seq.tryItem 3 { 10..20 } + let resultInt = Seq.tryItem 3 (seq { 10..20 }) Assert.AreEqual(Some(13), resultInt) // string Seq @@ -1976,11 +1976,11 @@ type SeqModule2() = CheckThrowsArgumentNullException (fun () -> Seq.tryItem 3 nullSeq |> ignore) // Negative index - let resultNegativeIndex = Seq.tryItem -1 { 10..20 } + let resultNegativeIndex = Seq.tryItem -1 (seq { 10..20 }) Assert.AreEqual(None, resultNegativeIndex) // Index greater than length - let resultIndexGreater = Seq.tryItem 31 { 10..20 } + let resultIndexGreater = Seq.tryItem 31 (seq { 10..20 }) Assert.AreEqual(None, resultIndexGreater) [] diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs index 8e24be62850..68692f65c67 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs @@ -821,7 +821,7 @@ module internal RangeTestsHelpers = enumerator.Current |> ignore let inline exceptions zero one two = - Assert.Throws (typeof, (fun () -> {one .. zero .. two} |> Seq.length |> ignore)) |> ignore + Assert.Throws (typeof, (fun () -> seq {one .. zero .. two} |> Seq.length |> ignore)) |> ignore Assert.Throws (typeof, (fun () -> [one .. zero .. two] |> List.length |> ignore)) |> ignore Assert.Throws (typeof, (fun () -> [|one .. zero .. two|] |> Array.length |> ignore)) |> ignore @@ -831,10 +831,10 @@ module internal RangeTestsHelpers = Assert.Throws (typeof, (fun () -> regressionExceptionAfterEndVariableStepIntegralRange zero two)) |> ignore let inline common (min0, min1, min2, min3) (max0, max1, max2, max3) (zero, one, two, three) = - Assert.AreEqual (seq {yield min0; yield min1; yield min2; yield min3}, {min0 .. min3}) - Assert.AreEqual (seq {min0; min1; min2; min3}, {min0 .. one .. min3}) - Assert.AreEqual (seq {min0; min2}, {min0 .. two .. min3}) - Assert.AreEqual (seq {min0; min3}, {min0 .. three .. min3}) + Assert.AreEqual (seq {yield min0; yield min1; yield min2; yield min3}, seq {min0 .. min3}) + Assert.AreEqual (seq {min0; min1; min2; min3}, seq {min0 .. one .. min3}) + Assert.AreEqual (seq {min0; min2}, seq {min0 .. two .. min3}) + Assert.AreEqual (seq {min0; min3}, seq {min0 .. three .. min3}) Assert.AreEqual ([min0; min1; min2; min3], [min0 .. min3]) Assert.AreEqual ([min0; min1; min2; min3], [min0 .. one .. min3]) @@ -846,10 +846,10 @@ module internal RangeTestsHelpers = Assert.AreEqual ([|min0; min2|], [|min0 .. two .. min3|]) Assert.AreEqual ([|min0; min3|], [|min0 .. three .. min3|]) - Assert.AreEqual (seq {yield max3; yield max2; yield max1; yield max0}, {max3 .. max0}) - Assert.AreEqual (seq {max3; max2; max1; max0}, {max3 .. one .. max0}) - Assert.AreEqual (seq {max3; max1}, {max3 .. two .. max0}) - Assert.AreEqual (seq {max3; max0}, {max3 .. three .. max0}) + Assert.AreEqual (seq {yield max3; yield max2; yield max1; yield max0}, seq {max3 .. max0}) + Assert.AreEqual (seq {max3; max2; max1; max0}, seq {max3 .. one .. max0}) + Assert.AreEqual (seq {max3; max1}, seq {max3 .. two .. max0}) + Assert.AreEqual (seq {max3; max0}, seq {max3 .. three .. max0}) Assert.AreEqual ([max3; max2; max1; max0], [max3 .. max0]) Assert.AreEqual ([max3; max2; max1; max0], [max3 .. one .. max0]) @@ -861,10 +861,10 @@ module internal RangeTestsHelpers = Assert.AreEqual ([|max3; max1|], [|max3 .. two .. max0|]) Assert.AreEqual ([|max3; max0|], [|max3 .. three .. max0|]) - Assert.AreEqual (Seq.empty, {max0 .. min0}) - Assert.AreEqual (Seq.empty, {max0 .. one .. min0}) - Assert.AreEqual (Seq.empty, {max0 .. two .. min0}) - Assert.AreEqual (Seq.empty, {max0 .. three .. min0}) + Assert.AreEqual (Seq.empty, seq {max0 .. min0}) + Assert.AreEqual (Seq.empty, seq {max0 .. one .. min0}) + Assert.AreEqual (Seq.empty, seq {max0 .. two .. min0}) + Assert.AreEqual (Seq.empty, seq {max0 .. three .. min0}) Assert.AreEqual ([], [max0 .. min0]) Assert.AreEqual ([], [max0 .. one .. min0]) @@ -880,8 +880,8 @@ module internal RangeTestsHelpers = // tests for singleStepRangeEnumerator, as it only is used if start and/or end are not the // minimum or maximum of the number range and it is counting by 1s - Assert.AreEqual (seq {min1; min2; min3}, {min1 .. min3}) - Assert.AreEqual (seq {max3; max2; max1}, {max3 .. max1}) + Assert.AreEqual (seq {min1; min2; min3}, seq {min1 .. min3}) + Assert.AreEqual (seq {max3; max2; max1}, seq {max3 .. max1}) Assert.AreEqual ([min1; min2; min3], [min1 .. min3]) Assert.AreEqual ([max3; max2; max1], [max3 .. max1]) @@ -903,10 +903,10 @@ module internal RangeTestsHelpers = common (min0, min1, min2, min3) (max0, max1, max2, max3) (zero, one, two, three) - Assert.AreEqual (seq { min0; min0 + max0; min0 + max0 + max0 }, {min0 .. max0 .. max0}) - Assert.AreEqual (seq { min0; min0 + max1; min0 + max1 + max1 }, {min0 .. max1 .. max0}) - Assert.AreEqual (seq { min0; min0 + max2; min0 + max2 + max2 }, {min0 .. max2 .. max0}) - Assert.AreEqual (seq { min0; min0 + max3; min0 + max3 + max3 }, {min0 .. max3 .. max0}) + Assert.AreEqual (seq { min0; min0 + max0; min0 + max0 + max0 }, seq {min0 .. max0 .. max0}) + Assert.AreEqual (seq { min0; min0 + max1; min0 + max1 + max1 }, seq {min0 .. max1 .. max0}) + Assert.AreEqual (seq { min0; min0 + max2; min0 + max2 + max2 }, seq {min0 .. max2 .. max0}) + Assert.AreEqual (seq { min0; min0 + max3; min0 + max3 + max3 }, seq {min0 .. max3 .. max0}) Assert.AreEqual ([ min0; min0 + max0; min0 + max0 + max0 ], [min0 .. max0 .. max0]) Assert.AreEqual ([ min0; min0 + max1; min0 + max1 + max1 ], [min0 .. max1 .. max0]) @@ -918,9 +918,9 @@ module internal RangeTestsHelpers = Assert.AreEqual ([| min0; min0 + max2; min0 + max2 + max2 |], [|min0 .. max2 .. max0|]) Assert.AreEqual ([| min0; min0 + max3; min0 + max3 + max3 |], [|min0 .. max3 .. max0|]) - Assert.AreEqual (seq {min3; min2; min1; min0}, {min3 .. -one .. min0}) - Assert.AreEqual (seq {min3; min1}, {min3 .. -two .. min0}) - Assert.AreEqual (seq {min3; min0}, {min3 .. -three .. min0}) + Assert.AreEqual (seq {min3; min2; min1; min0}, seq {min3 .. -one .. min0}) + Assert.AreEqual (seq {min3; min1}, seq {min3 .. -two .. min0}) + Assert.AreEqual (seq {min3; min0}, seq {min3 .. -three .. min0}) Assert.AreEqual ([min3; min2; min1; min0], [min3 .. -one .. min0]) Assert.AreEqual ([min3; min1], [min3 .. -two .. min0]) @@ -930,9 +930,9 @@ module internal RangeTestsHelpers = Assert.AreEqual ([|min3; min1|], [|min3 .. -two .. min0|]) Assert.AreEqual ([|min3; min0|], [|min3 .. -three .. min0|]) - Assert.AreEqual (seq {max0; max1; max2; max3}, {max0 .. -one .. max3}) - Assert.AreEqual (seq {max0; max2}, {max0 .. -two .. max3}) - Assert.AreEqual (seq {max0; max3}, {max0 .. -three .. max3}) + Assert.AreEqual (seq {max0; max1; max2; max3}, seq {max0 .. -one .. max3}) + Assert.AreEqual (seq {max0; max2}, seq {max0 .. -two .. max3}) + Assert.AreEqual (seq {max0; max3}, seq {max0 .. -three .. max3}) Assert.AreEqual ([max0; max1; max2; max3], [max0 .. -one .. max3]) Assert.AreEqual ([max0; max2], [max0 .. -two .. max3]) @@ -942,9 +942,9 @@ module internal RangeTestsHelpers = Assert.AreEqual ([|max0; max2|], [|max0 .. -two .. max3|]) Assert.AreEqual ([|max0; max3|], [|max0 .. -three .. max3|]) - Assert.AreEqual (Seq.empty, {min0 .. -one .. max0}) - Assert.AreEqual (Seq.empty, {min0 .. -two .. max0}) - Assert.AreEqual (Seq.empty, {min0 .. -three .. max0}) + Assert.AreEqual (Seq.empty, seq {min0 .. -one .. max0}) + Assert.AreEqual (Seq.empty, seq {min0 .. -two .. max0}) + Assert.AreEqual (Seq.empty, seq {min0 .. -three .. max0}) Assert.AreEqual ([], [min0 .. -one .. max0]) Assert.AreEqual ([], [min0 .. -two .. max0]) @@ -954,10 +954,10 @@ module internal RangeTestsHelpers = Assert.AreEqual ([||], [|min0 .. -two .. max0|]) Assert.AreEqual ([||], [|min0 .. -three .. max0|]) - Assert.AreEqual (seq {max0; max0 + min0}, {max0 .. min0 .. min0}) - Assert.AreEqual (seq {max0; max0 + min1; max0 + min1 + min1 }, {max0 .. min1 .. min0}) - Assert.AreEqual (seq {max0; max0 + min2; max0 + min2 + min2 }, {max0 .. min2 .. min0}) - Assert.AreEqual (seq {max0; max0 + min3; max0 + min3 + min3 }, {max0 .. min3 .. min0}) + Assert.AreEqual (seq {max0; max0 + min0}, seq {max0 .. min0 .. min0}) + Assert.AreEqual (seq {max0; max0 + min1; max0 + min1 + min1 }, seq {max0 .. min1 .. min0}) + Assert.AreEqual (seq {max0; max0 + min2; max0 + min2 + min2 }, seq {max0 .. min2 .. min0}) + Assert.AreEqual (seq {max0; max0 + min3; max0 + min3 + min3 }, seq {max0 .. min3 .. min0}) Assert.AreEqual ([max0; max0 + min0], [max0 .. min0 .. min0]) Assert.AreEqual ([max0; max0 + min1; max0 + min1 + min1 ], [max0 .. min1 .. min0]) @@ -983,10 +983,10 @@ module internal RangeTestsHelpers = common (min0, min1, min2, min3) (max0, max1, max2, max3) (zero, one, two, three) - Assert.AreEqual (seq {yield min0; yield min0 + max0}, {min0 .. max0 .. max0}) - Assert.AreEqual (seq {min0; min0 + max1}, {min0 .. max1 .. max0}) - Assert.AreEqual (seq {min0; min0 + max2}, {min0 .. max2 .. max0}) - Assert.AreEqual (seq {min0; min0 + max3}, {min0 .. max3 .. max0}) + Assert.AreEqual (seq {yield min0; yield min0 + max0}, seq {min0 .. max0 .. max0}) + Assert.AreEqual (seq {min0; min0 + max1}, seq {min0 .. max1 .. max0}) + Assert.AreEqual (seq {min0; min0 + max2}, seq {min0 .. max2 .. max0}) + Assert.AreEqual (seq {min0; min0 + max3}, seq {min0 .. max3 .. max0}) Assert.AreEqual ([min0; min0 + max0], [min0 .. max0 .. max0]) Assert.AreEqual ([min0; min0 + max1], [min0 .. max1 .. max0]) @@ -1064,15 +1064,15 @@ module RangeTests = Assert.AreEqual(256, let mutable c = 0 in for _ in System.SByte.MinValue..1y..System.SByte.MaxValue do c <- c + 1 done; c) Assert.AreEqual(256, let mutable c = 0 in for _ in System.SByte.MaxValue .. -1y .. System.SByte.MinValue do c <- c + 1 done; c) - Assert.AreEqual(allSBytesSeq, {System.SByte.MinValue..System.SByte.MaxValue}) + Assert.AreEqual(allSBytesSeq, seq {System.SByte.MinValue..System.SByte.MaxValue}) Assert.AreEqual(allSBytesList, [System.SByte.MinValue..System.SByte.MaxValue]) Assert.AreEqual(allSBytesArray, [|System.SByte.MinValue..System.SByte.MaxValue|]) - Assert.AreEqual(allSBytesSeq, {System.SByte.MinValue..1y..System.SByte.MaxValue}) + Assert.AreEqual(allSBytesSeq, seq {System.SByte.MinValue..1y..System.SByte.MaxValue}) Assert.AreEqual(allSBytesList, [System.SByte.MinValue..1y..System.SByte.MaxValue]) Assert.AreEqual(allSBytesArray, [|System.SByte.MinValue..1y..System.SByte.MaxValue|]) - Assert.AreEqual(Seq.rev allSBytesSeq, {System.SByte.MaxValue .. -1y .. System.SByte.MinValue}) + Assert.AreEqual(Seq.rev allSBytesSeq, seq {System.SByte.MaxValue .. -1y .. System.SByte.MinValue}) Assert.AreEqual(List.rev allSBytesList, [System.SByte.MaxValue .. -1y .. System.SByte.MinValue]) Assert.AreEqual(Array.rev allSBytesArray, [|System.SByte.MaxValue .. -1y .. System.SByte.MinValue|]) @@ -1083,11 +1083,11 @@ module RangeTests = Assert.AreEqual(256, let mutable c = 0 in for _ in System.Byte.MinValue..System.Byte.MaxValue do c <- c + 1 done; c) Assert.AreEqual(256, let mutable c = 0 in for _ in System.Byte.MinValue..1uy..System.Byte.MaxValue do c <- c + 1 done; c) - Assert.AreEqual(allBytesSeq, {System.Byte.MinValue..System.Byte.MaxValue}) + Assert.AreEqual(allBytesSeq, seq {System.Byte.MinValue..System.Byte.MaxValue}) Assert.AreEqual(allBytesList, [System.Byte.MinValue..System.Byte.MaxValue]) Assert.AreEqual(allBytesArray, [|System.Byte.MinValue..System.Byte.MaxValue|]) - Assert.AreEqual(allBytesSeq, {System.Byte.MinValue..1uy..System.Byte.MaxValue}) + Assert.AreEqual(allBytesSeq, seq {System.Byte.MinValue..1uy..System.Byte.MaxValue}) Assert.AreEqual(allBytesList, [System.Byte.MinValue..1uy..System.Byte.MaxValue]) Assert.AreEqual(allBytesArray, [|System.Byte.MinValue..1uy..System.Byte.MaxValue|]) @@ -1141,15 +1141,15 @@ module RangeTests = Assert.AreEqual(256, let mutable c = 0 in for _ in min0..one..max0 do c <- c + 1 done; c) Assert.AreEqual(256, let mutable c = 0 in for _ in max0 .. -one .. min0 do c <- c + 1 done; c) - Assert.AreEqual(allSBytesSeq, {min0..max0}) + Assert.AreEqual(allSBytesSeq, seq {min0..max0}) Assert.AreEqual(allSBytesList, [min0..max0]) Assert.AreEqual(allSBytesArray, [|min0..max0|]) - Assert.AreEqual(allSBytesSeq, {min0..one..max0}) + Assert.AreEqual(allSBytesSeq, seq {min0..one..max0}) Assert.AreEqual(allSBytesList, [min0..one..max0]) Assert.AreEqual(allSBytesArray, [|min0..one..max0|]) - Assert.AreEqual(Seq.rev allSBytesSeq, {max0 .. -one .. min0}) + Assert.AreEqual(Seq.rev allSBytesSeq, seq {max0 .. -one .. min0}) Assert.AreEqual(List.rev allSBytesList, [max0 .. -one .. min0]) Assert.AreEqual(Array.rev allSBytesArray, [|max0 .. -one .. min0|]) @@ -1160,11 +1160,11 @@ module RangeTests = Assert.AreEqual(256, let mutable c = 0 in for _ in min0..max0 do c <- c + 1 done; c) Assert.AreEqual(256, let mutable c = 0 in for _ in min0..one..max0 do c <- c + 1 done; c) - Assert.AreEqual(allBytesSeq, {min0..max0}) + Assert.AreEqual(allBytesSeq, seq {min0..max0}) Assert.AreEqual(allBytesList, [min0..max0]) Assert.AreEqual(allBytesArray, [|min0..max0|]) - Assert.AreEqual(allBytesSeq, {min0..one..max0}) + Assert.AreEqual(allBytesSeq, seq {min0..one..max0}) Assert.AreEqual(allBytesList, [min0..one..max0]) Assert.AreEqual(allBytesArray, [|min0..one..max0|]) diff --git a/tests/FSharp.Core.UnitTests/TestFrameworkHelpers.fs b/tests/FSharp.Core.UnitTests/TestFrameworkHelpers.fs index d5fe22cc3b3..31a699ae586 100644 --- a/tests/FSharp.Core.UnitTests/TestFrameworkHelpers.fs +++ b/tests/FSharp.Core.UnitTests/TestFrameworkHelpers.fs @@ -72,7 +72,7 @@ module private Impl = let ub = a1.GetUpperBound(0) if lb <> a2.GetLowerBound(0) || ub <> a2.GetUpperBound(0) then false else - {lb..ub} |> Seq.forall(fun i -> equals (a1.GetValue(i)) (a2.GetValue(i))) + seq {lb..ub} |> Seq.forall(fun i -> equals (a1.GetValue(i)) (a2.GetValue(i))) | _ -> Object.Equals(expected, actual) From bce0a6950d94feae0bfc1fcbe98c3cac0ce84917 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 22 Sep 2024 15:19:57 +0100 Subject: [PATCH 04/14] 3873., chkDeprecatePlacesWhereSeqCanBeOmitted --- .../Expressions/CheckSequenceExpressions.fs | 2 +- src/Compiler/FSComp.txt | 3 +- src/Compiler/xlf/FSComp.txt.cs.xlf | 7 +- src/Compiler/xlf/FSComp.txt.de.xlf | 7 +- src/Compiler/xlf/FSComp.txt.es.xlf | 7 +- src/Compiler/xlf/FSComp.txt.fr.xlf | 7 +- src/Compiler/xlf/FSComp.txt.it.xlf | 7 +- src/Compiler/xlf/FSComp.txt.ja.xlf | 7 +- src/Compiler/xlf/FSComp.txt.ko.xlf | 7 +- src/Compiler/xlf/FSComp.txt.pl.xlf | 7 +- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 7 +- src/Compiler/xlf/FSComp.txt.ru.xlf | 7 +- src/Compiler/xlf/FSComp.txt.tr.xlf | 7 +- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 7 +- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 7 +- .../DeprecatePlacesWhereSeqCanBeOmitted.fs | 57 +++++ .../Language/SequenceExpressionTests.fs | 205 ++++-------------- 17 files changed, 184 insertions(+), 174 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs diff --git a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs index d3e92e8b71d..4064d37e372 100644 --- a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs @@ -451,7 +451,7 @@ let TcSequenceExpressionEntry (cenv: TcFileState) env (overallTy: OverallTy) tpe && not hasBuilder && not cenv.g.compilingFSharpCore then - warning (Error(FSComp.SR.tcInvalidSequenceExpressionSyntaxForm (), m)) + warning (Error(FSComp.SR.chkDeprecatePlacesWhereSeqCanBeOmitted (), m)) TcExpr cenv overallTy env tpenv replacementExpr | None -> diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 2742af0437f..9a6b69fa2ff 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -591,7 +591,7 @@ tcCouldNotFindIDisposable,"Couldn't find Dispose on IDisposable, or it was overl 737,tcExpressionRequiresSequence,"This expression form may only be used in sequence and computation expressions" 738,tcInvalidObjectExpressionSyntaxForm,"Invalid object expression. Objects without overrides or interfaces should use the expression form 'new Type(args)' without braces." 739,tcInvalidObjectSequenceOrRecordExpression,"Invalid object, sequence or record expression" -740,tcInvalidSequenceExpressionSyntaxForm,"Sequence expressions should be of the form 'seq {{ ... }}'" +740,tcInvalidSequenceExpressionSyntaxForm,"Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}'" tcExpressionWithIfRequiresParenthesis,"This list or array expression includes an element of the form 'if ... then ... else'. Parenthesize this expression to indicate it is an individual element of the list or array, to disambiguate this from a list generated using a sequence expression" 741,tcUnableToParseFormatString,"Unable to parse format string '%s'" 742,tcListLiteralMaxSize,"This list expression exceeds the maximum size for list literals. Use an array for larger literals and call Array.ToList." @@ -1784,4 +1784,5 @@ featureAllowAccessModifiersToAutoPropertiesGettersAndSetters,"Allow access modif 3871,tcAccessModifiersNotAllowedInSRTPConstraint,"Access modifiers cannot be applied to an SRTP constraint." featureAllowObjectExpressionWithoutOverrides,"Allow object expressions without overrides" 3872,tcPartialActivePattern,"Multi-case partial active patterns are not supported. Consider using a single-case partial active pattern or a full active pattern." +3873,chkDeprecatePlacesWhereSeqCanBeOmitted,"This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}'" featureDeprecatePlacesWhereSeqCanBeOmitted,"Deprecate places where 'seq' can be omitted" \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 3cbd52e47ee..97c0076a602 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -52,6 +52,11 @@ Tento výraz je anonymní záznam, použijte {{|...|}} místo {{...}}. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Duplicitní parametr Parametr {0} byl v této metodě použit vícekrát. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Neplatný výraz záznamu, pořadí nebo výpočtu. Výrazy pořadí by měly mít notaci seq {{ ... }}. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index a5d23b6e395..f3cc32967b8 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -52,6 +52,11 @@ Dieser Ausdruck ist ein anonymer Datensatz. Verwenden Sie {{|...|}} anstelle von {{...}}. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Doppelter Parameter. Der Parameter „{0}“ wurde in dieser Methode mehrmals verwendet. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Ungültiger Datensatz-, Sequenz- oder Berechnungsausdruck. Sequenzausdrücke müssen das Format "seq {{ ... }}" besitzen. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 2afe39f5603..e594a0e30a8 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -52,6 +52,11 @@ Esta expresión es un registro anónimo; use {{|...|}} en lugar de {{...}}. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Parámetro duplicado. El parámetro '{0}' se ha usado más una vez en este método. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Expresión de registro, secuencia o cómputo no válida. Las expresiones de secuencia deben tener el formato 'seq {{ ... }}'. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index e596ed29a75..41f7aefd63d 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -52,6 +52,11 @@ Cette expression est un enregistrement anonyme, utilisez {{|...|}} au lieu de {{...}}. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Paramètre dupliqué. Le paramètre « {0} » a été utilisé une fois de plus dans cette méthode. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Expression d'enregistrement, de séquence ou de calcul non valide. Les expressions de séquence doivent avoir le format 'seq {{ ... }}' diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 1ac4d6cdb42..d53f5993cb0 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -52,6 +52,11 @@ Questa espressione è un record anonimo. Usa {{|...|}} invece di {{...}}. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Parametro duplicato. Il parametro '{0}' è stato utilizzato più volte in questo metodo. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Espressione di calcolo, sequenza o record non valida. Il formato delle espressioni sequenza deve essere 'seq {{ ... }}' diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index a42fe7d8286..c7cbc9d3eef 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -52,6 +52,11 @@ この式は匿名レコードであり、{{...}} の代わりに {{|...|}} を使用してください。 + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. パラメーターが重複しています。パラメーター '{0}' は、このメソッドで 1 回以上使用されています。 @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' 無効なレコード、シーケンス式、またはコンピュテーション式です。シーケンス式は 'seq {{ ... }}' という形式にしてください。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index d8626088a97..8cb24073c9d 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -52,6 +52,11 @@ 이 식은 익명 레코드입니다. {{...}} 대신 {{|...|}}을 사용하세요. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. 매개 변수가 중복되었습니다. 이 메소드에서 매개 변수 '{0}'이(가) 두 번 이상 사용되었습니다. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' 레코드, 시퀀스 또는 계산 식이 잘못되었습니다. 시퀀스 식의 형식은 'seq {{ ... }}'여야 합니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index f1b1b1fc426..78d8496fff9 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -52,6 +52,11 @@ To wyrażenie jest rekordem anonimowym. Użyj {{|...|}} zamiast {{...}}. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Zduplikowany parametr. Parametr „{0}” został użyty więcej niż raz w tej metodzie. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Nieprawidłowe wyrażenie rekordu, sekwencji lub obliczenia. Wyrażenia sekwencji powinny mieć postać „seq {{ ... }}” diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index ca7bdaa1427..72c04e45b62 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -52,6 +52,11 @@ Esta expressão é um registro anônimo, use {{|...|}} em vez de {{...}}. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Parâmetro duplicado. O parâmetro '{0}' foi usado mais de uma vez neste método. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Expressão de registro, sequência ou computação inválida. Expressões de sequência devem estar na forma 'seq {{ ... }}' diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 3b75c3d71a9..1d5693bd034 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -52,6 +52,11 @@ Это выражение является анонимной записью. Используйте {{|...|}} вместо {{...}}. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Повторяющийся параметр. Параметр "{0}" использовался в этом методе несколько раз. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Недопустимая запись, выражение последовательности или вычислительное выражение. Выражения последовательностей должны иметь форму "seq {{ ... }}' diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index ae649852d4d..5db06220a89 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -52,6 +52,11 @@ Bu ifade, anonim bir kayıt, {{...}} yerine {{|...|}} kullanın. + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. Yinelenen parametre. '{0}' parametresi bu metotta bir kereden fazla kullanıldı. @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' Geçersiz kayıt, dizi veya hesaplama ifadesi. Dizi ifadeleri 'seq {{ ... }}' biçiminde olmalıdır diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 6706ef41a76..666b9594453 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -52,6 +52,11 @@ 此表达式是匿名记录,请使用 {{|...|}} 而不是 {{...}}。 + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. 参数重复。此方法中多次使用了参数“{0}”。 @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' 记录、序列或计算表达式无效。序列表达式的格式应为“seq {{ ... }}” diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 97e4901139d..78bac458187 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -52,6 +52,11 @@ 此運算式是匿名記錄,請使用 {{|...|}} 而不是 {{...}}。 + + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}' + + Duplicate parameter. The parameter '{0}' has been used more that once in this method. 重複的參數。參數 '{0}' 在此方法中使用多次。 @@ -4528,7 +4533,7 @@ - Sequence expressions should be of the form 'seq {{ ... }}' + Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq {{ ... }}' 無效的記錄、循序項或計算運算式。循序項運算式應該是 'seq {{ ... }}' 形式。 diff --git a/tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs b/tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs new file mode 100644 index 00000000000..fba7388b7f8 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs @@ -0,0 +1,57 @@ +{ 1..10 } + +{ 1..5..10 } + +[| { 1..10 } |] + +[| { 1..5..10 } |] + +let a = { 1..10 } + +let a3 = { 1..10..20 } + +let b = [| { 1..10 } |] + +let b3 = [| { 1..10..20 } |] + +let c = [ { 1..10 } ] + +[| { 1..10 } |] + +[| yield { 1..10 } |] + +[ { 1..10 } ] + +[ { 1..10..10 } ] + +[ yield { 1..10 } ] + +[ yield { 1..10..20 } ] + +ResizeArray({ 1..10 }) + +ResizeArray({ 1..10..20 }) + +let fw start finish = [ for x in { start..finish } -> x ] + +let fe start finish = [| for x in { start..finish } -> x |] + +for x in { 1..10 } do () + +for x in { 1..5..10 } do () + +let f = Seq.head + +let a2 = f { 1..6 } + +let a23 = f { 1..6..10 } + +let b2 = set { 1..6 } + +let f10 start finish = for x in { start..finish } do ignore (float x ** float x) + +let (..) _ _ = "lol" + +let lol1 = { 1..10 } + +{ 1..5..10 } \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs index 5b4b7a7985b..216294c8b47 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs @@ -2,6 +2,7 @@ module Language.SequenceExpressionTests +open FSharp.Test open Xunit open FSharp.Test.Compiler open FSharp.Test.ScriptHelpers @@ -457,11 +458,11 @@ let c = [ { 1;10 } ] |> typecheck |> shouldFail |> withDiagnostics [ - (Error 740, Line 2, Col 1, Line 2, Col 9, "Sequence expressions should be of the form 'seq { ... }'") - (Error 740, Line 3, Col 4, Line 3, Col 12, "Sequence expressions should be of the form 'seq { ... }'") - (Error 740, Line 4, Col 9, Line 4, Col 17, "Sequence expressions should be of the form 'seq { ... }'") - (Error 740, Line 5, Col 12, Line 5, Col 20, "Sequence expressions should be of the form 'seq { ... }'") - (Error 740, Line 6, Col 11, Line 6, Col 19, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 2, Col 1, Line 2, Col 9, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 3, Col 4, Line 3, Col 12, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 4, Col 9, Line 4, Col 17, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 5, Col 12, Line 5, Col 20, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 6, Col 11, Line 6, Col 19, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") ] [] @@ -478,170 +479,56 @@ let c = [ { 1;10 } ] |> typecheck |> shouldFail |> withDiagnostics [ - (Error 740, Line 2, Col 1, Line 2, Col 9, "Sequence expressions should be of the form 'seq { ... }'") - (Error 740, Line 3, Col 4, Line 3, Col 12, "Sequence expressions should be of the form 'seq { ... }'") - (Error 740, Line 4, Col 9, Line 4, Col 17, "Sequence expressions should be of the form 'seq { ... }'") - (Error 740, Line 5, Col 12, Line 5, Col 20, "Sequence expressions should be of the form 'seq { ... }'") - (Error 740, Line 6, Col 11, Line 6, Col 19, "Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 2, Col 1, Line 2, Col 9, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 3, Col 4, Line 3, Col 12, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 4, Col 9, Line 4, Col 17, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 5, Col 12, Line 5, Col 20, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 6, Col 11, Line 6, Col 19, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") ] -[] -let ``Sequence(SynExpr.IndexRange) expressions should be of the form 'seq { ... } lang version 9``() = - Fsx """ -{ 1..10 } - -{ 1..5..10 } - -[| { 1..10 } |] - -[| { 1..5..10 } |] - -let a = { 1..10 } - -let a3 = { 1..10..20 } - -let b = [| { 1..10 } |] - -let b3 = [| { 1..10..20 } |] - -let c = [ { 1..10 } ] - -[| { 1..10 } |] - -[| yield { 1..10 } |] - -[ { 1..10 } ] - -[ { 1..10..10 } ] - -[ yield { 1..10 } ] - -[ yield { 1..10..20 } ] - -ResizeArray({ 1..10 }) - -ResizeArray({ 1..10..20 }) - -let fw start finish = [ for x in { start..finish } -> x ] - -let fe start finish = [| for x in { start..finish } -> x |] - -for x in { 1..10 } do () - -for x in { 1..5..10 } do () - -let f = Seq.head - -let a2 = f { 1..6 } - -let a23 = f { 1..6..10 } - -let b2 = set { 1..6 } - -let f10 start finish = for x in { start..finish } do ignore (float x ** float x) - -let (..) _ _ = "lol" - -let lol1 = { 1..10 } - -{ 1..5..10 } - """ +// SOURCE=DeprecatePlacesWhereSeqCanBeOmitted.fs # DeprecatePlacesWhereSeqCanBeOmitted.fs +[] +let ``IndexRangeWithoutSeq lang version 9`` compilation = + compilation |> withOptions [ "--nowarn:0020" ] |> withLangVersion90 |> typecheck |> shouldSucceed -[] -let ``Sequence(SynExpr.IndexRange) expressions should be of the form 'seq { ... }``() = - Fsx """ -{ 1..10 } - -{ 1..5..10 } - -[| { 1..10 } |] - -[| { 1..5..10 } |] - -let a = { 1..10 } - -let a3 = { 1..10..20 } - -let b = [| { 1..10 } |] - -let b3 = [| { 1..10..20 } |] - -let c = [ { 1..10 } ] - -[| { 1..10 } |] - -[| yield { 1..10 } |] - -[ { 1..10 } ] - -[ { 1..10..10 } ] - -[ yield { 1..10 } ] - -[ yield { 1..10..20 } ] - -ResizeArray({ 1..10 }) - -ResizeArray({ 1..10..20 }) - -let fw start finish = [ for x in { start..finish } -> x ] - -let fe start finish = [| for x in { start..finish } -> x |] - -for x in { 1..10 } do () - -for x in { 1..5..10 } do () - -let f = Seq.head - -let a2 = f { 1..6 } - -let a23 = f { 1..6..10 } - -let b2 = set { 1..6 } - -let f10 start finish = for x in { start..finish } do ignore (float x ** float x) - -let (..) _ _ = "lol" - -let lol1 = { 1..10 } - -{ 1..5..10 } - """ +// SOURCE=DeprecatePlacesWhereSeqCanBeOmitted.fs # DeprecatePlacesWhereSeqCanBeOmitted.fs +[] +let ``E_IndexRangeWithoutSeq lang version preview`` compilation = + compilation |> withOptions [ "--nowarn:0020" ] |> withLangVersionPreview |> typecheck |> shouldFail |> withDiagnostics [ - (Warning 740, Line 2, Col 1, Line 2, Col 10, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 4, Col 1, Line 4, Col 13, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 6, Col 4, Line 6, Col 13, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 8, Col 4, Line 8, Col 16, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 10, Col 9, Line 10, Col 18, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 12, Col 10, Line 12, Col 23, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 14, Col 12, Line 14, Col 21, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 16, Col 13, Line 16, Col 26, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 18, Col 11, Line 18, Col 20, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 20, Col 4, Line 20, Col 13, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 22, Col 10, Line 22, Col 19, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 24, Col 3, Line 24, Col 12, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 26, Col 3, Line 26, Col 16, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 28, Col 9, Line 28, Col 18, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 30, Col 9, Line 30, Col 22, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 32, Col 13, Line 32, Col 22, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 34, Col 13, Line 34, Col 26, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 36, Col 34, Line 36, Col 51, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 38, Col 35, Line 38, Col 52, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 40, Col 10, Line 40, Col 19, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 42, Col 10, Line 42, Col 22, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 46, Col 12, Line 46, Col 20, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 48, Col 13, Line 48, Col 25, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 50, Col 14, Line 50, Col 22, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 52, Col 33, Line 52, Col 50, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 56, Col 12, Line 56, Col 21, "Sequence expressions should be of the form 'seq { ... }'"); - (Warning 740, Line 58, Col 1, Line 58, Col 13, "Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 1, Col 1, Line 1, Col 10, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 3, Col 1, Line 3, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 5, Col 4, Line 5, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 7, Col 4, Line 7, Col 16, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 9, Col 9, Line 9, Col 18, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 11, Col 10, Line 11, Col 23, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 13, Col 12, Line 13, Col 21, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 15, Col 13, Line 15, Col 26, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 17, Col 11, Line 17, Col 20, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 19, Col 4, Line 19, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 21, Col 10, Line 21, Col 19, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 23, Col 3, Line 23, Col 12, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 25, Col 3, Line 25, Col 16, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 27, Col 9, Line 27, Col 18, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 29, Col 9, Line 29, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 31, Col 13, Line 31, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 33, Col 13, Line 33, Col 26, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 35, Col 34, Line 35, Col 51, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 37, Col 35, Line 37, Col 52, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 39, Col 10, Line 39, Col 19, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 41, Col 10, Line 41, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 45, Col 12, Line 45, Col 20, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 47, Col 13, Line 47, Col 25, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 49, Col 14, Line 49, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 51, Col 33, Line 51, Col 50, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 55, Col 12, Line 55, Col 21, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 57, Col 1, Line 57, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") ] \ No newline at end of file From 37b5ab81e0640bffa77e4f3eeed71551c3d12cbd Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 22 Sep 2024 18:39:02 +0100 Subject: [PATCH 05/14] more tests --- .../Expressions/CheckSequenceExpressions.fs | 2 +- .../DeprecatePlacesWhereSeqCanBeOmitted.fs | 21 ++++++++++++++++++- .../Language/SequenceExpressionTests.fs | 14 +++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs index 4064d37e372..8e762952f0c 100644 --- a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs @@ -466,6 +466,6 @@ let TcSequenceExpressionEntry (cenv: TcFileState) env (overallTy: OverallTy) tpe | _ -> () if not hasBuilder && not cenv.g.compilingFSharpCore then - errorR (Error(FSComp.SR.tcInvalidSequenceExpressionSyntaxForm (), m)) + error (Error(FSComp.SR.tcInvalidSequenceExpressionSyntaxForm (), m)) TcSequenceExpression cenv env tpenv comp overallTy m diff --git a/tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs b/tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs index fba7388b7f8..37ca58c3db6 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs @@ -54,4 +54,23 @@ let (..) _ _ = "lol" let lol1 = { 1..10 } -{ 1..5..10 } \ No newline at end of file +{ 1..5..10 } + +let resultInt = Seq.length {1..8} + +let resultInt2 funcInt = Seq.map3 funcInt { 1..8 } { 2..9 } { 3..10 } + +let verify c = failwith "not implemented" + +Seq.splitInto 4 {1..5} |> verify { 1.. 10 } + +seq [ {1..4}; {5..7}; {8..10} ] + +Seq.allPairs { 1..7 } Seq.empty + +Seq.allPairs Seq.empty { 1..7 } + +let intArr1 = [| yield! {1..100} + yield! {1..100} |] + +Array.ofSeq {1..10} \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs index 216294c8b47..181dc2145ea 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs @@ -531,4 +531,18 @@ let ``E_IndexRangeWithoutSeq lang version preview`` compilation = (Warning 3873, Line 51, Col 33, Line 51, Col 50, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") (Warning 3873, Line 55, Col 12, Line 55, Col 21, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") (Warning 3873, Line 57, Col 1, Line 57, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 59, Col 28, Line 59, Col 34, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 61, Col 44, Line 61, Col 52, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 61, Col 53, Line 61, Col 61, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 61, Col 62, Line 61, Col 71, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 65, Col 17, Line 65, Col 23, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 65, Col 34, Line 65, Col 44, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 67, Col 7, Line 67, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 67, Col 15, Line 67, Col 21, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 67, Col 23, Line 67, Col 30, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 69, Col 14, Line 69, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 71, Col 24, Line 71, Col 32, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 73, Col 25, Line 73, Col 33, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 74, Col 25, Line 74, Col 33, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 76, Col 13, Line 76, Col 20, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") ] \ No newline at end of file From a731f2f4b11ca126047bce239abfb74460e394d9 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 22 Sep 2024 18:39:13 +0100 Subject: [PATCH 06/14] release notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 2 +- docs/release-notes/.Language/preview.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index a2a0f964f7f..6fe40e2d6fe 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -2,7 +2,7 @@ ### Added - +* Deprecate places where `seq` can be omitted. ([Language suggestion #1033](https://github.com/fsharp/fslang-suggestions/issues/1033), [PR #17772](https://github.com/dotnet/fsharp/pull/17772)) ### Changed diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md index b18d08e30c3..a38e14215dc 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -1,6 +1,7 @@ ### Added * Better generic unmanaged structs handling. ([Language suggestion #692](https://github.com/fsharp/fslang-suggestions/issues/692), [PR #12154](https://github.com/dotnet/fsharp/pull/12154)) +* Deprecate places where `seq` can be omitted. ([Language suggestion #1033](https://github.com/fsharp/fslang-suggestions/issues/1033), [PR #17772](https://github.com/dotnet/fsharp/pull/17772)) ### Fixed From 0d13e00cf56d817df6c451e22736c0d82a2808c4 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 22 Sep 2024 21:41:05 +0100 Subject: [PATCH 07/14] reorg seq tests --- .../FSharp.Compiler.ComponentTests.fsproj | 2 +- .../E_SequenceExpressions01.fs} | 0 .../SequenceExpressionTests.fs | 34 +++++++-- .../SequenceExpressions01.fs | 76 +++++++++++++++++++ 4 files changed, 103 insertions(+), 9 deletions(-) rename tests/FSharp.Compiler.ComponentTests/Language/{DeprecatePlacesWhereSeqCanBeOmitted.fs => SequenceExpressions/E_SequenceExpressions01.fs} (100%) rename tests/FSharp.Compiler.ComponentTests/Language/{ => SequenceExpressions}/SequenceExpressionTests.fs (94%) create mode 100644 tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressions01.fs diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 03ff28e096a..303974168db 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -221,6 +221,7 @@ + @@ -235,7 +236,6 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/E_SequenceExpressions01.fs similarity index 100% rename from tests/FSharp.Compiler.ComponentTests/Language/DeprecatePlacesWhereSeqCanBeOmitted.fs rename to tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/E_SequenceExpressions01.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs similarity index 94% rename from tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs rename to tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs index 181dc2145ea..5d75beb5fed 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -module Language.SequenceExpressionTests +module Language.SequenceExpression.SequenceExpressionTests open FSharp.Test open Xunit @@ -486,18 +486,18 @@ let c = [ { 1;10 } ] (Error 740, Line 6, Col 11, Line 6, Col 19, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") ] -// SOURCE=DeprecatePlacesWhereSeqCanBeOmitted.fs # DeprecatePlacesWhereSeqCanBeOmitted.fs -[] -let ``IndexRangeWithoutSeq lang version 9`` compilation = +// SOURCE=E_SequenceExpressions01.fs # E_SequenceExpressions01.fs +[] +let ``E_SequenceExpressions01 lang version 9`` compilation = compilation |> withOptions [ "--nowarn:0020" ] |> withLangVersion90 |> typecheck |> shouldSucceed -// SOURCE=DeprecatePlacesWhereSeqCanBeOmitted.fs # DeprecatePlacesWhereSeqCanBeOmitted.fs -[] -let ``E_IndexRangeWithoutSeq lang version preview`` compilation = +// SOURCE=E_SequenceExpressions01.fs # E_SequenceExpressions01.fs +[] +let ``E_SequenceExpressions01 lang version preview`` compilation = compilation |> withOptions [ "--nowarn:0020" ] |> withLangVersionPreview @@ -545,4 +545,22 @@ let ``E_IndexRangeWithoutSeq lang version preview`` compilation = (Warning 3873, Line 73, Col 25, Line 73, Col 33, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") (Warning 3873, Line 74, Col 25, Line 74, Col 33, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") (Warning 3873, Line 76, Col 13, Line 76, Col 20, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") - ] \ No newline at end of file + ] + +// SOURCE=SequenceExpressions01.fs # SequenceExpressions01.fs +[] +let ``SequenceExpressions01 lang version 9`` compilation = + compilation + |> withOptions [ "--nowarn:0020" ] + |> withLangVersion90 + |> typecheck + |> shouldSucceed + +// SOURCE=SequenceExpressions01.fs # SequenceExpressions01.fs +[] +let ``SequenceExpressions01 lang version preview`` compilation = + compilation + |> withOptions [ "--nowarn:0020" ] + |> withLangVersionPreview + |> typecheck + |> shouldSucceed \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressions01.fs b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressions01.fs new file mode 100644 index 00000000000..ea1ab603eef --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressions01.fs @@ -0,0 +1,76 @@ +seq { 1..10 } + +seq { 1..5..10 } + +[| seq { 1..10 } |] + +[| seq { 1..5..10 } |] + +let a = seq { 1..10 } + +let a3 = seq { 1..10..20 } + +let b = [| seq { 1..10 } |] + +let b3 = [| seq { 1..10..20 } |] + +let c = [ seq { 1..10 } ] + +[| seq { 1..10 } |] + +[| yield seq { 1..10 } |] + +[ seq { 1..10 } ] + +[ seq { 1..10..10 } ] + +[ yield seq { 1..10 } ] + +[ yield seq { 1..10..20 } ] + +ResizeArray(seq { 1..10 }) + +ResizeArray(seq { 1..10..20 }) + +let fw start finish = [ for x in seq { start..finish } -> x ] + +let fe start finish = [| for x in seq { start..finish } -> x |] + +for x in seq { 1..10 } do () + +for x in seq { 1..5..10 } do () + +let f = Seq.head + +let a2 = f (seq { 1..6 }) + +let a23 = f (seq { 1..6..10 }) + +let b2 = set (seq { 1..6 }) + +let f10 start finish = for x in seq { start..finish } do ignore (float x ** float x) + +let (..) _ _ = "lol" + +let lol1 = seq { 1..10 } + +seq { 1..5..10 } + +let resultInt = Seq.length (seq {1..8}) + +let resultInt2 funcInt = Seq.map3 funcInt (seq { 1..8 }) (seq { 2..9 }) (seq { 3..10 }) + +let verify c = failwith "not implemented" + +Seq.splitInto 4 (seq {1..5}) |> verify (seq { 1.. 10 }) + +seq [ seq {1..4}; seq {5..7}; seq {8..10} ] + +Seq.allPairs (seq { 1..7 }) Seq.empty + +Seq.allPairs Seq.empty (seq { 1..7 }) + +let intArr1 = [| yield! seq {1..100} + yield! seq {1..100} |] + +Array.ofSeq (seq {1..10}) \ No newline at end of file From de89b448f134dca611cf3f715daaf3712b76de04 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sat, 28 Sep 2024 15:34:17 +0100 Subject: [PATCH 08/14] Better check --- .../Checking/Expressions/CheckExpressions.fs | 11 +++++++++++ .../Expressions/CheckSequenceExpressions.fs | 13 +------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index d2df1aff642..cc5075b9a78 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -5890,6 +5890,17 @@ and TcExprUndelayed (cenv: cenv) (overallTy: OverallTy) env tpenv (synExpr: SynE TcForEachExpr cenv overallTy env tpenv (seqExprOnly, isFromSource, pat, synEnumExpr, synBodyExpr, m, spFor, spIn, m) | SynExpr.ComputationExpr (hasSeqBuilder, comp, m) -> + let isIndexRange = match comp with | SynExpr.IndexRange _ -> true | _ -> false + let deprecatedPlacesWhereSeqCanBeOmitted = + cenv.g.langVersion.SupportsFeature LanguageFeature.DeprecatePlacesWhereSeqCanBeOmitted + if + deprecatedPlacesWhereSeqCanBeOmitted + && isIndexRange + && not hasSeqBuilder + && not cenv.g.compilingFSharpCore + then + warning (Error(FSComp.SR.chkDeprecatePlacesWhereSeqCanBeOmitted (), m)) + let env = ExitFamilyRegion env cenv.TcSequenceExpressionEntry cenv env overallTy tpenv (hasSeqBuilder, comp) m diff --git a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs index 37ccbded82b..b627eef2922 100644 --- a/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs @@ -442,18 +442,7 @@ let TcSequenceExpression (cenv: TcFileState) env tpenv comp (overallTy: OverallT let TcSequenceExpressionEntry (cenv: TcFileState) env (overallTy: OverallTy) tpenv (hasBuilder, comp) m = match RewriteRangeExpr comp with - | Some replacementExpr -> - let deprecatedPlacesWhereSeqCanBeOmitted = - cenv.g.langVersion.SupportsFeature LanguageFeature.DeprecatePlacesWhereSeqCanBeOmitted - - if - deprecatedPlacesWhereSeqCanBeOmitted - && not hasBuilder - && not cenv.g.compilingFSharpCore - then - warning (Error(FSComp.SR.chkDeprecatePlacesWhereSeqCanBeOmitted (), m)) - - TcExpr cenv overallTy env tpenv replacementExpr + | Some replacementExpr -> TcExpr cenv overallTy env tpenv replacementExpr | None -> let implicitYieldEnabled = cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield From 10dc2ee87c49ed9ce26313a78ff76621377ddabc Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 8 Oct 2024 13:07:19 +0100 Subject: [PATCH 09/14] fix merge conflicts --- .../SequenceExpressionTests.fs | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs index 6de58a5ab34..263f305f7a5 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs @@ -469,3 +469,124 @@ let f2 = return! [ 3; 4 ] (Error 748, Line 2, Col 10, Line 2, Col 16, "This construct may only be used within computation expressions. To return a value from an ordinary function simply write the expression without 'return'."); (Error 748, Line 3, Col 10, Line 3, Col 17, "This construct may only be used within computation expressions. To return a value from an ordinary function simply write the expression without 'return'.") ] + +[] +let ``Sequence(SynExpr.Sequential) expressions should be of the form 'seq { ... } lang version 9``() = + Fsx """ +{ 1;10 } +[| { 1;10 } |] +let a = { 1;10 } +let b = [| { 1;10 } |] +let c = [ { 1;10 } ] + """ + |> withOptions [ "--nowarn:0020" ] + |> withLangVersion90 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 740, Line 2, Col 1, Line 2, Col 9, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 3, Col 4, Line 3, Col 12, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 4, Col 9, Line 4, Col 17, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 5, Col 12, Line 5, Col 20, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 6, Col 11, Line 6, Col 19, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + ] + +[] +let ``Sequence(SynExpr.Sequential) expressions should be of the form 'seq { ... } lang version preview``() = + Fsx """ +{ 1;10 } +[| { 1;10 } |] +let a = { 1;10 } +let b = [| { 1;10 } |] +let c = [ { 1;10 } ] + """ + |> withOptions [ "--nowarn:0020" ] + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 740, Line 2, Col 1, Line 2, Col 9, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 3, Col 4, Line 3, Col 12, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 4, Col 9, Line 4, Col 17, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 5, Col 12, Line 5, Col 20, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + (Error 740, Line 6, Col 11, Line 6, Col 19, "Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'") + ] + +// SOURCE=E_SequenceExpressions01.fs # E_SequenceExpressions01.fs +[] +let ``E_SequenceExpressions01 lang version 9`` compilation = + compilation + |> withOptions [ "--nowarn:0020" ] + |> withLangVersion90 + |> typecheck + |> shouldSucceed + +// SOURCE=E_SequenceExpressions01.fs # E_SequenceExpressions01.fs +[] +let ``E_SequenceExpressions01 lang version preview`` compilation = + compilation + |> withOptions [ "--nowarn:0020" ] + |> withLangVersionPreview + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 3873, Line 1, Col 1, Line 1, Col 10, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 3, Col 1, Line 3, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 5, Col 4, Line 5, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 7, Col 4, Line 7, Col 16, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 9, Col 9, Line 9, Col 18, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 11, Col 10, Line 11, Col 23, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 13, Col 12, Line 13, Col 21, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 15, Col 13, Line 15, Col 26, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 17, Col 11, Line 17, Col 20, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 19, Col 4, Line 19, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 21, Col 10, Line 21, Col 19, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 23, Col 3, Line 23, Col 12, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 25, Col 3, Line 25, Col 16, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 27, Col 9, Line 27, Col 18, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 29, Col 9, Line 29, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 31, Col 13, Line 31, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 33, Col 13, Line 33, Col 26, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 35, Col 34, Line 35, Col 51, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 37, Col 35, Line 37, Col 52, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 39, Col 10, Line 39, Col 19, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 41, Col 10, Line 41, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 45, Col 12, Line 45, Col 20, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 47, Col 13, Line 47, Col 25, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 49, Col 14, Line 49, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 51, Col 33, Line 51, Col 50, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 55, Col 12, Line 55, Col 21, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 57, Col 1, Line 57, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 59, Col 28, Line 59, Col 34, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 61, Col 44, Line 61, Col 52, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 61, Col 53, Line 61, Col 61, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 61, Col 62, Line 61, Col 71, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 65, Col 17, Line 65, Col 23, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 65, Col 34, Line 65, Col 44, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 67, Col 7, Line 67, Col 13, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 67, Col 15, Line 67, Col 21, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 67, Col 23, Line 67, Col 30, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 69, Col 14, Line 69, Col 22, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 71, Col 24, Line 71, Col 32, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 73, Col 25, Line 73, Col 33, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 74, Col 25, Line 74, Col 33, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + (Warning 3873, Line 76, Col 13, Line 76, Col 20, "This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'") + ] + +// SOURCE=SequenceExpressions01.fs # SequenceExpressions01.fs +[] +let ``SequenceExpressions01 lang version 9`` compilation = + compilation + |> withOptions [ "--nowarn:0020" ] + |> withLangVersion90 + |> typecheck + |> shouldSucceed + +// SOURCE=SequenceExpressions01.fs # SequenceExpressions01.fs +[] +let ``SequenceExpressions01 lang version preview`` compilation = + compilation + |> withOptions [ "--nowarn:0020" ] + |> withLangVersionPreview + |> typecheck + |> shouldSucceed \ No newline at end of file From 07955068028bd2412d5e174fceb061e8fb2ec75a Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 18 Oct 2024 20:07:34 -0400 Subject: [PATCH 10/14] =?UTF-8?q?Add=20code=20fix=20for=20adding=20missing?= =?UTF-8?q?=20`seq`=20before=20`{=E2=80=A6}`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FSharp.Editor/CodeFixes/AddMissingSeq.fs | 79 +++++++++++ .../src/FSharp.Editor/Common/Constants.fs | 3 + .../src/FSharp.Editor/FSharp.Editor.fsproj | 1 + .../src/FSharp.Editor/FSharp.Editor.resx | 3 + .../FSharp.Editor/xlf/FSharp.Editor.cs.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.de.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.es.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.fr.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.it.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.ja.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.ko.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.pl.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.ru.xlf | 5 + .../FSharp.Editor/xlf/FSharp.Editor.tr.xlf | 5 + .../xlf/FSharp.Editor.zh-Hans.xlf | 5 + .../xlf/FSharp.Editor.zh-Hant.xlf | 5 + .../CodeFixes/AddMissingSeqTests.fs | 126 ++++++++++++++++++ .../FSharp.Editor.Tests.fsproj | 1 + 19 files changed, 278 insertions(+) create mode 100644 vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs create mode 100644 vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs diff --git a/vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs b/vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs new file mode 100644 index 00000000000..7c6513df77e --- /dev/null +++ b/vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace Microsoft.VisualStudio.FSharp.Editor + +open System.Collections.Immutable +open System.Composition +open FSharp.Compiler.Syntax +open FSharp.Compiler.Text +open Microsoft.CodeAnalysis.CodeFixes +open Microsoft.CodeAnalysis.Text +open CancellableTasks + +[] +[] +type internal AddMissingSeqCodeFixProvider() = + inherit CodeFixProvider() + + static let title = SR.AddMissingSeq() + static let fixableDiagnosticIds = ImmutableArray.Create("FS3873", "FS0740") + + override _.FixableDiagnosticIds = fixableDiagnosticIds + + override this.RegisterCodeFixesAsync context = context.RegisterFsharpFix this + + override this.GetFixAllProvider() = this.RegisterFsharpFixAll() + + interface IFSharpCodeFixProvider with + member _.GetCodeFixIfAppliesAsync context = + cancellableTask { + let! sourceText = context.GetSourceTextAsync() + let! parseFileResults = context.Document.GetFSharpParseResultsAsync(nameof AddMissingSeqCodeFixProvider) + + let getSourceLineStr line = + sourceText.Lines[Line.toZ line].ToString() + + let range = + RoslynHelpers.TextSpanToFSharpRange(context.Document.FilePath, context.Span, sourceText) + + let needsParens = + (range.Start, parseFileResults.ParseTree) + ||> ParsedInput.exists (fun path node -> + match path, node with + | SyntaxNode.SynExpr outer :: _, SyntaxNode.SynExpr(expr & SynExpr.ComputationExpr _) when + expr.Range |> Range.equals range + -> + let seqRange = + range + |> Range.withEnd (Position.mkPos range.Start.Line (range.Start.Column + 3)) + + let inner = + SynExpr.App( + ExprAtomicFlag.NonAtomic, + false, + SynExpr.Ident(Ident(nameof seq, seqRange)), + expr, + Range.unionRanges seqRange expr.Range + ) + + let outer = + match outer with + | SynExpr.App(flag, isInfix, funcExpr, _, outerAppRange) -> + SynExpr.App(flag, isInfix, funcExpr, inner, outerAppRange) + | outer -> outer + + inner + |> SynExpr.shouldBeParenthesizedInContext getSourceLineStr (SyntaxNode.SynExpr outer :: path) + | _ -> false) + + let text = sourceText.ToString(TextSpan(context.Span.Start, context.Span.Length)) + let newText = if needsParens then $"(seq {text})" else $"seq {text}" + + return + ValueSome + { + Name = CodeFix.AddMissingSeq + Message = title + Changes = [ TextChange(context.Span, newText) ] + } + } diff --git a/vsintegration/src/FSharp.Editor/Common/Constants.fs b/vsintegration/src/FSharp.Editor/Common/Constants.fs index 822af01d16a..24ee22eb433 100644 --- a/vsintegration/src/FSharp.Editor/Common/Constants.fs +++ b/vsintegration/src/FSharp.Editor/Common/Constants.fs @@ -208,3 +208,6 @@ module internal CodeFix = [] let RemoveUnnecessaryParentheses = "RemoveUnnecessaryParentheses" + + [] + let AddMissingSeq = "AddMissingSeq" diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj index 37bb02d43d2..2ec608dda20 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj @@ -141,6 +141,7 @@ + diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx index 26b96dcc405..fac57e8b469 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.resx +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.resx @@ -359,6 +359,9 @@ Use live (unsaved) buffers for analysis Remove unnecessary parentheses + + Add missing 'seq' + Remarks: diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf index 421cc037111..7f7c1064aad 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf @@ -17,6 +17,11 @@ Přidat chybějící parametr člena instance + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword Přidejte klíčové slovo new. diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf index ff2a415b3a0..4117ecceddc 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf @@ -17,6 +17,11 @@ Fehlenden Instanzmemberparameter hinzufügen + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword Schlüsselwort "new" hinzufügen diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf index 5df84b54acc..729a252061a 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf @@ -17,6 +17,11 @@ Agregar parámetro de miembro de instancia que falta + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword Agregar "nueva" palabra clave diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf index efe15d65037..a49ba5d1a13 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf @@ -17,6 +17,11 @@ Ajouter un paramètre de membre d’instance manquant + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword Ajouter le mot clé 'new' diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf index ca32c029946..0f82d483df8 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf @@ -17,6 +17,11 @@ Aggiungi parametro membro di istanza mancante + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword Aggiungi la parola chiave 'new' diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf index 44ca609e1cd..71c981ec17c 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf @@ -17,6 +17,11 @@ 見つからないインスタンス メンバー パラメーターを追加する + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword 'new' キーワードを追加する diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf index 66cfbeed575..776efa37ca0 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf @@ -17,6 +17,11 @@ 누락된 인스턴스 멤버 매개 변수 추가 + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword 'new' 키워드 추가 diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf index 1675887bd6d..d4b1c40cd09 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf @@ -17,6 +17,11 @@ Dodaj brakujący parametr składowej wystąpienia + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword Dodaj słowo kluczowe „new” diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf index f6770d970de..d743e4f549d 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf @@ -17,6 +17,11 @@ Adicionar parâmetro de membro de instância ausente + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword Adicionar a palavra-chave 'new' diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf index bc8554237a8..623dbc446f3 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf @@ -17,6 +17,11 @@ Добавить отсутствующий параметр экземплярного элемента + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword Добавить ключевое слово "new" diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf index cf2198ba7d3..d652ca45127 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf @@ -17,6 +17,11 @@ Eksik örnek üye parametresini ekleyin + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword 'new' anahtar sözcüğünü ekleme diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf index 16a89acc021..e0d31417ab4 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf @@ -17,6 +17,11 @@ 添加缺少的实例成员参数 + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword 添加“新”关键字 diff --git a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf index 932d4de3e61..89f6de50bcd 100644 --- a/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf +++ b/vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf @@ -17,6 +17,11 @@ 新增缺少的執行個體成員參數 + + Add missing 'seq' + Add missing 'seq' + + Add 'new' keyword 新增 'new' 關鍵字 diff --git a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs new file mode 100644 index 00000000000..835b16d7cee --- /dev/null +++ b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +module FSharp.Editor.Tests.CodeFixes.AddMissingSeqTests + +open Microsoft.VisualStudio.FSharp.Editor +open Xunit +open CodeFixTestFramework + +let private codeFix = AddMissingSeqCodeFixProvider() + +// This can be changed to Auto when featureDeprecatePlacesWhereSeqCanBeOmitted is out of preview. +let mode = WithOption "--langversion:preview" + +[] +let ``FS3873 — Adds missing seq before { start..finish }`` () = + let code = "let xs = { 1..10 }" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let xs = seq { 1..10 }" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + +[] +let ``FS0740 — Adds missing seq before { x; y }`` () = + let code = "let xs = { 1; 10 }" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let xs = seq { 1; 10 }" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + +[] +let ``FS3873 — Adds parens when needed`` () = + let code = "let xs = id { 1..10 }" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let xs = id (seq { 1..10 })" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + +[] +let ``FS0740 — Adds parens when needed`` () = + let code = "let xs = id { 1; 10 }" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let xs = id (seq { 1; 10 })" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + +[] +let ``FS3873 — Adds parens when needed — multiline`` () = + let code = + """ +let xs = + id { + 1..10 + } +""" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = + """ +let xs = + id (seq { + 1..10 + }) +""" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + +[] +let ``FS0740 — Adds parens when needed — multiline`` () = + let code = + """ +let xs = + id { + 1; 10 + } +""" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = + """ +let xs = + id (seq { + 1; 10 + }) +""" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) diff --git a/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj b/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj index a180accc43f..738a3e1323c 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj +++ b/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj @@ -72,6 +72,7 @@ + From 3e0c4c7ccb69ebe03518cf2e2c0fb644a4389744 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 18 Oct 2024 20:25:59 -0400 Subject: [PATCH 11/14] More tests --- .../CodeFixes/AddMissingSeqTests.fs | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs index 835b16d7cee..b62a8d0c798 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs @@ -42,7 +42,7 @@ let ``FS0740 — Adds missing seq before { x; y }`` () = Assert.Equal(expected, actual) [] -let ``FS3873 — Adds parens when needed`` () = +let ``FS3873 — Adds parens when needed — app`` () = let code = "let xs = id { 1..10 }" let expected = @@ -57,7 +57,22 @@ let ``FS3873 — Adds parens when needed`` () = Assert.Equal(expected, actual) [] -let ``FS0740 — Adds parens when needed`` () = +let ``FS3873 — Adds parens when needed — dot`` () = + let code = "let s = { 1..10 }.ToString ()" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let s = (seq { 1..10 }).ToString ()" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + +[] +let ``FS0740 — Adds parens when needed — app`` () = let code = "let xs = id { 1; 10 }" let expected = @@ -71,6 +86,21 @@ let ``FS0740 — Adds parens when needed`` () = Assert.Equal(expected, actual) +[] +let ``FS0740 — Adds parens when needed — dot`` () = + let code = "let s = { 1; 10 }.ToString ()" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let s = (seq { 1; 10 }).ToString ()" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + [] let ``FS3873 — Adds parens when needed — multiline`` () = let code = From 6f46629c986001f5be9147f2172ff39ad62cd0d2 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 18 Oct 2024 20:28:13 -0400 Subject: [PATCH 12/14] Fmt --- vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs | 2 -- 1 file changed, 2 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs b/vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs index 7c6513df77e..e9a5783bbb2 100644 --- a/vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs +++ b/vsintegration/src/FSharp.Editor/CodeFixes/AddMissingSeq.fs @@ -19,9 +19,7 @@ type internal AddMissingSeqCodeFixProvider() = static let fixableDiagnosticIds = ImmutableArray.Create("FS3873", "FS0740") override _.FixableDiagnosticIds = fixableDiagnosticIds - override this.RegisterCodeFixesAsync context = context.RegisterFsharpFix this - override this.GetFixAllProvider() = this.RegisterFsharpFixAll() interface IFSharpCodeFixProvider with From f698c119edd144c84ec7ddfa068e95d902f2925c Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sat, 19 Oct 2024 10:47:39 +0100 Subject: [PATCH 13/14] update release notes --- docs/release-notes/.VisualStudio/17.13.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docs/release-notes/.VisualStudio/17.13.md diff --git a/docs/release-notes/.VisualStudio/17.13.md b/docs/release-notes/.VisualStudio/17.13.md new file mode 100644 index 00000000000..dae07600e1b --- /dev/null +++ b/docs/release-notes/.VisualStudio/17.13.md @@ -0,0 +1,8 @@ +### Fixed + +### Added +* Code fix for adding missing `seq`. ([PR #17772](https://github.com/dotnet/fsharp/pull/17772)) + +### Changed + +### Breaking Changes From 9d24c546261b0555e396f0369c4dbd9aa90ef9c9 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sat, 19 Oct 2024 15:22:44 +0100 Subject: [PATCH 14/14] more editor tests --- .../CodeFixes/AddMissingSeqTests.fs | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs index b62a8d0c798..8a51be6a8fc 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/AddMissingSeqTests.fs @@ -26,6 +26,21 @@ let ``FS3873 — Adds missing seq before { start..finish }`` () = Assert.Equal(expected, actual) +[] +let ``FS3873 — Adds missing seq before { start..step..finish }`` () = + let code = "let xs = { 1..5..10 }" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let xs = seq { 1..5..10 }" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + [] let ``FS0740 — Adds missing seq before { x; y }`` () = let code = "let xs = { 1; 10 }" @@ -41,6 +56,44 @@ let ``FS0740 — Adds missing seq before { x; y }`` () = Assert.Equal(expected, actual) +[] +let ``FS3873 — Adds missing seq before yield { start..finish }`` () = + let code = "let xs = [| yield { 1..100 } |]" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let xs = [| yield seq { 1..100 } |]" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + +[] +let ``FS3873 — Adds missing seq before yield { start..finish } multiline`` () = + let code = + """ +let xs = [| yield seq { 1..100 } + yield { 1..100 } |] +""" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = + """ +let xs = [| yield seq { 1..100 } + yield seq { 1..100 } |] +""" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + [] let ``FS3873 — Adds parens when needed — app`` () = let code = "let xs = id { 1..10 }" @@ -56,6 +109,36 @@ let ``FS3873 — Adds parens when needed — app`` () = Assert.Equal(expected, actual) +[] +let ``FS3873 — Adds parens when needed — app parens`` () = + let code = "let xs = ResizeArray({ 1..10 })" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "let xs = ResizeArray(seq { 1..10 })" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + +[] +let ``FS3873 — Adds parens when needed — foreach`` () = + let code = "[ for x in { 1..10 } -> x ]" + + let expected = + Some + { + Message = "Add missing 'seq'" + FixedCode = "[ for x in seq { 1..10 } -> x ]" + } + + let actual = codeFix |> tryFix code mode + + Assert.Equal(expected, actual) + [] let ``FS3873 — Adds parens when needed — dot`` () = let code = "let s = { 1..10 }.ToString ()"