From d539f27ea04dad74d853b7fff19eb7ef79c63d10 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 20 Dec 2022 14:50:50 +0100 Subject: [PATCH 1/3] Prevent IDE crash in case of file duplicate in fsproj - Prevent IDE error in the first place - Report diagnostics in case of fsc.exe build - Report warning in case of service build - Fix bug in componenttest framework for .fsi compilation --- src/Compiler/Driver/CompilerOptions.fs | 17 ++++++++++++- src/Compiler/Driver/CompilerOptions.fsi | 2 ++ src/Compiler/Driver/fsc.fs | 1 + src/Compiler/FSComp.txt | 1 + src/Compiler/xlf/FSComp.txt.cs.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 ++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 ++++ .../CompilerOptions/fsc/sourceFiles.fs | 20 +++++++++++++++ .../Structure/UnionTypeWithSignature02.fs | 2 +- .../FSharp.Compiler.ComponentTests.fsproj | 1 + .../FSharpChecker/CommonWorkflows.fs | 10 ++++++++ tests/FSharp.Test.Utilities/Compiler.fs | 3 ++- .../ProjectGeneration.fs | 25 +++++++++++-------- 23 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/sourceFiles.fs diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index 5d80041645..bb9062dcc7 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -2304,6 +2304,21 @@ let GetCoreFsiCompilerOptions (tcConfigB: TcConfigBuilder) = ) ] +let CheckAndReportSourceFileDuplicates (sourceFiles : ResizeArray) = + let visited = Dictionary.newWithSize (sourceFiles.Count*2) + let count = sourceFiles.Count + [ + for i=0 to (count-1) do + let source = sourceFiles[i] + match visited.TryGetValue source with + | true, duplicatePosition -> + + warning(Error(FSComp.SR.buildDuplicateFile(source, i+1, count, duplicatePosition+1, count), range0 )) + | false, _ -> + visited.Add(source,i) + yield source + ] + let ApplyCommandLineArgs (tcConfigB: TcConfigBuilder, sourceFiles: string list, argv) = try let sourceFilesAcc = ResizeArray sourceFiles @@ -2313,7 +2328,7 @@ let ApplyCommandLineArgs (tcConfigB: TcConfigBuilder, sourceFiles: string list, sourceFilesAcc.Add name ParseCompilerOptions(collect, GetCoreServiceCompilerOptions tcConfigB, argv) - ResizeArray.toList sourceFilesAcc + sourceFilesAcc |> CheckAndReportSourceFileDuplicates with e -> errorRecovery e range0 sourceFiles diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 0915d99903..8ec35db75d 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -66,6 +66,8 @@ val GetCoreFsiCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list val GetCoreServiceCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list +val CheckAndReportSourceFileDuplicates: ResizeArray -> string list + /// Apply args to TcConfigBuilder and return new list of source files val ApplyCommandLineArgs: tcConfigB: TcConfigBuilder * sourceFiles: string list * argv: string list -> string list diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index 705d6bb383..efdace7b43 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -536,6 +536,7 @@ let main1 // Rather than start processing, just collect names, then process them. try let files = ProcessCommandLineFlags(tcConfigB, lcidFromCodePage, argv) + let files = CheckAndReportSourceFileDuplicates (ResizeArray.ofList files) AdjustForScriptCompile(tcConfigB, files, lexResourceManager, dependencyProvider) with e -> errorRecovery e rangeStartup diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index cb6bc023f8..e803f1a6ab 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1662,4 +1662,5 @@ reprStateMachineInvalidForm,"The state machine has an unexpected form" 3548,matchNotAllowedForUnionCaseWithNoData,"Pattern discard is not allowed for union case that takes no data." 3549,tcSynTypeOrInvalidInDeclaration,"SynType.Or is not permitted in this declaration" 3550,chkDuplicatedMethodParameter,"Duplicate parameter. The parameter '%s' has been used more that once in this method." +3551,buildDuplicateFile,"The source file '%s' (at position %d/%d) already appeared in the compilation list (at position %d/%d). Please verify that it is included only once in the project file." featureEscapeBracesInFormattableString,"Escapes curly braces before calling FormattableStringFactory.Create when interpolated string literal is typed as FormattableString" \ 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 a03a936bf4..b57d0f37d0 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. Soubor {0} má nerozpoznanou příponu. Zdrojové soubory musí mít příponu .fs, .fsi, .fsx nebo .fsscript. Pokud chcete povolit použití zastaralých přípon .ml nebo .mli, použijte parametry --langversion:5.0 a --mlcompatibility. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 88d360b25a..7de21f130d 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. Die Dateierweiterung von „{0}“ wurde nicht erkannt. Quelldateien müssen die Erweiterung .fs, .fsi, .fsx oder .fsscript haben. Um die veraltete Verwendung der Erweiterungen .ml oder .mli zu aktivieren, verwenden Sie „--langversion:5.0“ und „--mlcompatibility“. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 02122ba629..a602e0b822 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. No se reconoce la extensión de archivo de '{0}'. Los archivos de código fuente deben tener las extensiones .fs, .fsi, .fsx o .fsscript. Para habilitar el uso en desuso de las extensiones .ml o .mli, use '--langversion:5.0' y '--mlcompatibility'. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 483f8b91ba..d806154d6f 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. L’extension de fichier « {0} » n’est pas reconnue. Les fichiers sources doivent avoir l’extension. FS,. FSI,. FSX ou. fsscript. Pour activer l’utilisation déconseillée des extensions. ml ou. MLI, utilisez'--langversion : 5.0 'et'--mlcompatibility'. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 49cf9bad9b..06a164cf1d 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. L'estensione di file di '{0}' non è riconosciuta. I file di origine devono avere estensione fs, fsi, fsx o fsscript. Per abilitare l'uso deprecato delle estensioni ml o mli, usare '--langversion:5.0' e '--mlcompatibility'. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 0ed505a871..1b15cd752e 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. '{0}' のファイル拡張子を認識できません。ソース ファイル拡張子は .fs、.fsi、.fsx、または .fsscript にする必要があります。非推奨の拡張子 .ml または .mli の使用を有効にするには、'--langversion:5.0' および '--mlcompatibility' を使用してください。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 666a62143e..b095bffba3 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. '{0}'의 파일 확장자가 인식되지 않습니다. 원본 파일의 확장자는 .fs, .fsi, .fsx 또는 .fsscript여야 합니다. 더 이상 사용되지 않는 .ml 또는 .mli 확장자를 사용하려면 '--langversion:5.0' 및 '--mlcompatibility'를 사용하세요. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 35f555a08b..7b39e89b24 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. Rozszerzenie pliku "{0}" nie zostało rozpoznane. Pliki źródłowe muszą mieć rozszerzenie .fs, .fsi, .fsx lub .fsscript. Aby włączyć przestarzałe używanie rozszerzeń. ml lub .mli, użyj polecenia "--langversion: 5.0" i "--mlcompatibility". diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 7e4a20be7a..4c5d1ffdc0 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. A extensão do arquivo '{0}' não foi reconhecida. Os arquivos de origem devem ter a extensão .fs, .fsi, .fsx ou .fsscript. Para ativar o uso preterido das extensões .ml ou .mli, use '--langversion:5.0' e '--mlcompatibility'. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 4ab2847a18..20e65c4a4e 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. Расширение файла "{0}" не распознано. Исходные файлы должны иметь расширения FS, FSI, FSX или FSSCRIPT. Чтобы включить использование нерекомендуемых расширений ML или MLI, примените команду "--langversion:5.0" и "--mlcompatibility". diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 85cca20423..b200d2f5fc 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. '{0}' kaynak dosyasının dosya uzantısı tanınmadı. Kaynak dosyaların uzantısı .fs, .fsi, .fsx veya .fsscript olmalıdır. Kullanım dışı .ml veya .mli uzantılarını etkinleştirmek için '--langversion:5.0' ve '--mlcompatibility' kullanın. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 55f8ac8d9c..da9a46b686 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. 无法识别“{0}”的文件扩展名。源文件必须具有扩展名 .fs、.fsi、.fsx 或 .fsscript。要启用已弃用的 .ml 或 .mli 扩展名,请使用 “--langversion:5.0” 和 “--mlcompatibility”。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 02122cbd5c..0c9cb10abe 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -7,6 +7,11 @@ All elements of an array must be implicitly convertible to the type of the first element, which here is a tuple of length {0} of type\n {1} \nThis element is a tuple of length {2} of type\n {3} \n + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. + + The file extension of '{0}' is not recognized. Source files must have extension .fs, .fsi, .fsx or .fsscript. To enable the deprecated use of .ml or .mli extensions, use '--langversion:5.0' and '--mlcompatibility'. 無法辨識 '{0}' 的副檔名。來源檔案的副檔名必須是 fsi、.fsx 或 .fsscript。若要啟用已被取代的 .ml 或 .mli 副檔名,請使用 '--langversion:5.0' and '--mlcompatibility'。 diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/sourceFiles.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/sourceFiles.fs new file mode 100644 index 0000000000..9f467df00c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/sourceFiles.fs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +module FSharp.Compiler.ComponentTests.CompilerOptions.FscSourceFilesArguments + +open Xunit +open FSharp.Test +open FSharp.Test.Compiler + + +[] +let ``Reports duplicate sources via warning``() = + let file = SourceCodeFileKind.Fs({FileName="test.fs"; SourceText=Some """printfn "Hello" """ }) + + fsFromString file + |> FS + |> asExe + |> withAdditionalSourceFile file + |> compile + |> withWarningCodes [3551] + |> withErrorCodes [] \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Structure/UnionTypeWithSignature02.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Structure/UnionTypeWithSignature02.fs index f0d289ff54..92daf21dfd 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Structure/UnionTypeWithSignature02.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Structure/UnionTypeWithSignature02.fs @@ -2,7 +2,7 @@ // Regression test for FSHARP1.0:4040 // "Signature files do not prevent compiler-generated public constructors from leaking out of discriminated unions" // Note that the corresponsing .fsi file is NOT missing the "| C of int" part of the DU -namespace N +module N type T = | C of int diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 7627368cc5..acc8cb2247 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -198,6 +198,7 @@ + diff --git a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs index 1afd0d5622..562df05190 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs @@ -89,3 +89,13 @@ let ``Changes in a referenced project`` () = saveFile "Library" checkFile "Last" expectSignatureChanged } + +[] +let ``Language service works if the same file is listed twice`` () = + let file = sourceFile "First" [] + let project = SyntheticProject.Create(file) + project.Workflow { + checkFile "First" expectOk + addFileAbove "First" file + checkFile "First" (expectSingleWarningAndNoErrors "Please verify that it is included only once in the project file.") + } \ No newline at end of file diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 97808b5859..116499498b 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -193,7 +193,7 @@ module rec Compiler = // Load the source file from the path let loadSourceFromFile path = getSource(TestType.Path path) - let private fsFromString (source: SourceCodeFileKind): FSharpCompilationSource = + let fsFromString (source: SourceCodeFileKind): FSharpCompilationSource = { Source = source AdditionalSources = [] @@ -321,6 +321,7 @@ module rec Compiler = let asFs (cUnit: CompilationUnit) : CompilationUnit = match cUnit with + | FS { Source = SourceCodeFileKind.Fsi _} -> cUnit | FS src -> FS {src with Source=SourceCodeFileKind.Fs({FileName=src.Source.GetSourceFileName; SourceText=src.Source.GetSourceText})} | _ -> failwith "Only F# compilation can be of type Fs." diff --git a/tests/FSharp.Test.Utilities/ProjectGeneration.fs b/tests/FSharp.Test.Utilities/ProjectGeneration.fs index 19de591038..3d9c4f9f52 100644 --- a/tests/FSharp.Test.Utilities/ProjectGeneration.fs +++ b/tests/FSharp.Test.Utilities/ProjectGeneration.fs @@ -222,15 +222,6 @@ module Internal = let content = renderSourceFile p f writeFileIfChanged fileName content - let validateFileIdsAreUnique (project: SyntheticProject) = - let ids = [ for _, f in project.GetAllFiles() -> f.Id ] - let duplicates = ids |> List.groupBy id |> List.filter (fun (_, g) -> g.Length > 1) - - if duplicates.Length > 0 then - failwith - $"""Source file IDs have to be unique across the project and all referenced projects. Found duplicates: {String.Join(", ", duplicates |> List.map fst)}""" - - open Internal @@ -311,6 +302,21 @@ module ProjectOperations = if checkResult.Diagnostics.Length > 0 then failwith $"Expected no errors, but there were some: \n%A{checkResult.Diagnostics}" + let expectSingleWarningAndNoErrors (warningSubString:string) parseAndCheckResults _ = + let checkResult = getTypeCheckResult parseAndCheckResults + let errors = checkResult.Diagnostics|> Array.filter (fun d -> d.Severity = FSharpDiagnosticSeverity.Error) + if errors.Length > 0 then + failwith $"Expected no errors, but there were some: \n%A{errors}" + + let warnings = checkResult.Diagnostics|> Array.filter (fun d -> d.Severity = FSharpDiagnosticSeverity.Warning) + match warnings |> Array.tryExactlyOne with + | None -> failwith $"Expected 1 warning, but got {warnings.Length} instead: \n%A{warnings}" + | Some w -> + if w.Message.Contains warningSubString then + () + else + failwith $"Expected 1 warning with substring '{warningSubString}' but got %A{w}" + let expectErrors parseAndCheckResults _ = let checkResult = getTypeCheckResult parseAndCheckResults @@ -378,7 +384,6 @@ type WorkflowContext = let SaveAndCheckProject project checker = async { - validateFileIdsAreUnique project do! saveProject project true checker From 4acd1d0fd676f21058b7687353dafeaacc65d64d Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 20 Dec 2022 14:57:12 +0100 Subject: [PATCH 2/3] fantomas --- src/Compiler/Driver/CompilerOptions.fs | 18 ++++++++++-------- src/Compiler/Driver/CompilerOptions.fsi | 2 +- src/Compiler/Driver/fsc.fs | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index bb9062dcc7..7291316ac8 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -2304,18 +2304,20 @@ let GetCoreFsiCompilerOptions (tcConfigB: TcConfigBuilder) = ) ] -let CheckAndReportSourceFileDuplicates (sourceFiles : ResizeArray) = - let visited = Dictionary.newWithSize (sourceFiles.Count*2) +let CheckAndReportSourceFileDuplicates (sourceFiles: ResizeArray) = + let visited = Dictionary.newWithSize (sourceFiles.Count * 2) let count = sourceFiles.Count + [ - for i=0 to (count-1) do + for i = 0 to (count - 1) do let source = sourceFiles[i] + match visited.TryGetValue source with - | true, duplicatePosition -> - - warning(Error(FSComp.SR.buildDuplicateFile(source, i+1, count, duplicatePosition+1, count), range0 )) - | false, _ -> - visited.Add(source,i) + | true, duplicatePosition -> + + warning (Error(FSComp.SR.buildDuplicateFile (source, i + 1, count, duplicatePosition + 1, count), range0)) + | false, _ -> + visited.Add(source, i) yield source ] diff --git a/src/Compiler/Driver/CompilerOptions.fsi b/src/Compiler/Driver/CompilerOptions.fsi index 8ec35db75d..286816018e 100644 --- a/src/Compiler/Driver/CompilerOptions.fsi +++ b/src/Compiler/Driver/CompilerOptions.fsi @@ -66,7 +66,7 @@ val GetCoreFsiCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list val GetCoreServiceCompilerOptions: TcConfigBuilder -> CompilerOptionBlock list -val CheckAndReportSourceFileDuplicates: ResizeArray -> string list +val CheckAndReportSourceFileDuplicates: ResizeArray -> string list /// Apply args to TcConfigBuilder and return new list of source files val ApplyCommandLineArgs: tcConfigB: TcConfigBuilder * sourceFiles: string list * argv: string list -> string list diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index efdace7b43..b5623036f5 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -536,7 +536,7 @@ let main1 // Rather than start processing, just collect names, then process them. try let files = ProcessCommandLineFlags(tcConfigB, lcidFromCodePage, argv) - let files = CheckAndReportSourceFileDuplicates (ResizeArray.ofList files) + let files = CheckAndReportSourceFileDuplicates(ResizeArray.ofList files) AdjustForScriptCompile(tcConfigB, files, lexResourceManager, dependencyProvider) with e -> errorRecovery e rangeStartup From 322daea0b2bb60b8e7fb89977be85cabf70fbac8 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 27 Dec 2022 13:02:10 +0100 Subject: [PATCH 3/3] Updating perl based gcc test to use fsc.exe correctly (no duplicate file listing) --- tests/fsharpqa/Source/CompilerOptions/fsc/gccerrors/env.lst | 2 +- tests/fsharpqa/Source/test.lst | 2 +- tests/fsharpqa/run.fsharpqa.test.fsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/gccerrors/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/gccerrors/env.lst index e45bfc1834..f66e0766f8 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/gccerrors/env.lst +++ b/tests/fsharpqa/Source/CompilerOptions/fsc/gccerrors/env.lst @@ -1 +1 @@ -ReqENU SOURCE=gccerrors01.fs COMPILE_ONLY=1 SCFLAGS="--gccerrors --nologo gccerrors01.fs >gccerrors01.txt" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx gccerrors01.txt gccerrors01.bsl" +ReqENU SOURCE=gccerrors01.fs COMPILE_ONLY=1 SCFLAGS="--gccerrors --nologo >gccerrors01.txt" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx gccerrors01.txt gccerrors01.bsl" diff --git a/tests/fsharpqa/Source/test.lst b/tests/fsharpqa/Source/test.lst index e72cbd1161..2c9482e246 100644 --- a/tests/fsharpqa/Source/test.lst +++ b/tests/fsharpqa/Source/test.lst @@ -10,7 +10,7 @@ CompilerOptions01,NoMT CompilerOptions\fsc\crossoptimize CompilerOptions01,NoMT,Determinism CompilerOptions\fsc\determinism CompilerOptions01,NoMT CompilerOptions\fsc\dumpAllCommandLineOptions CompilerOptions01,NoMT CompilerOptions\fsc\flaterrors -CompilerOptions02,NoMT CompilerOptions\fsc\gccerrors +CompilerOptions02,NoMT,gcc CompilerOptions\fsc\gccerrors CompilerOptions01,NoMT,help CompilerOptions\fsc\help CompilerOptions01,NoMT CompilerOptions\fsc\highentropyva CompilerOptions01,NoMT CompilerOptions\fsc\langversion diff --git a/tests/fsharpqa/run.fsharpqa.test.fsx b/tests/fsharpqa/run.fsharpqa.test.fsx index 89006028a3..0d87d74240 100644 --- a/tests/fsharpqa/run.fsharpqa.test.fsx +++ b/tests/fsharpqa/run.fsharpqa.test.fsx @@ -60,4 +60,4 @@ let runPerl arguments = let testResultDir = Path.Combine(rootFolder, "tests", "TestResults") let perlScript = Path.Combine(rootFolder, "tests", "fsharpqa", "testenv", "bin", "runall.pl") -runPerl [|perlScript; "-resultsroot";testResultDir ;"-ttags:Determinism"|] \ No newline at end of file +runPerl [|perlScript; "-resultsroot";testResultDir ;"-ttags:gcc"|] \ No newline at end of file