From 75b9c5e3922dbfdb0eee3c9c40c33b5bf102db83 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 25 May 2026 10:39:00 +0200 Subject: [PATCH 1/2] Add FS3888 diagnostic for namespace/type collision When a namespace name collides with a type name across files in the same assembly, the compiler previously emitted FS0247 stating the partner was a module. The partner is actually a type, so emit the new FS3888 diagnostic in that case while keeping FS0247 for namespace/module collisions. Fixes #17827 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Compiler/FSComp.txt | 1 + .../TypedTree/TypedTreeOps.Remapping.fs | 5 ++- src/Compiler/xlf/FSComp.txt.cs.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.de.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.es.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.fr.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.it.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.ja.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.ko.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.pl.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.ru.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.tr.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 35 +++++++++++-------- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 35 +++++++++++-------- .../ErrorMessages/NamespaceTests.fs | 31 +++++++++++++++- 16 files changed, 295 insertions(+), 197 deletions(-) diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index f9765bdbd6e..8900f874517 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1818,4 +1818,5 @@ featurePreprocessorElif,"#elif preprocessor directive" 3885,parsLetBangCannotBeLastInCE,"'%s' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression." 3886,tcListLiteralWithSingleTupleElement,"This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements?" 3887,ilCustomAttrInvalidArrayElemType,"The type '%s' is not a valid custom attribute argument type. Custom attribute arrays must have elements of primitive types, enums, string, System.Type, or System.Object." +3888,tastNamespaceAndTypeWithSameNameInAssembly,"The namespace '%s' clashes with the type '%s'." featureExceptionFieldSerializationSupport,"emit GetObjectData and field-restoring deserialization constructor for exception types" diff --git a/src/Compiler/TypedTree/TypedTreeOps.Remapping.fs b/src/Compiler/TypedTree/TypedTreeOps.Remapping.fs index de28bc34138..4720e0e0ab8 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.Remapping.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.Remapping.fs @@ -622,8 +622,11 @@ module internal SignatureOps = match entity1.IsNamespace, entity2.IsNamespace, entity1.IsModule, entity2.IsModule with | true, true, _, _ -> () + | true, _, _, true + | _, true, true, _ -> errorR (Error(FSComp.SR.tastNamespaceAndModuleWithSameNameInAssembly (textOfPath path2), entity2.Range)) | true, _, _, _ - | _, true, _, _ -> errorR (Error(FSComp.SR.tastNamespaceAndModuleWithSameNameInAssembly (textOfPath path2), entity2.Range)) + | _, true, _, _ -> + errorR (Error(FSComp.SR.tastNamespaceAndTypeWithSameNameInAssembly (textOfPath path2, entity2.LogicalName), entity2.Range)) | false, false, false, false -> errorR (Error(FSComp.SR.tastDuplicateTypeDefinitionInAssembly (entity2.LogicalName, textOfPath path), entity2.Range)) | false, false, true, true -> errorR (Error(FSComp.SR.tastTwoModulesWithSameNameInAssembly (textOfPath path2), entity2.Range)) diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 10fe84e6ab1..ab2d8c44957 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -1352,6 +1352,11 @@ (Navržený název) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 17f93260936..a82134281e2 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -1352,6 +1352,11 @@ (Empfohlener Name) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index ecc7e4a3f27..64e90494f33 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -1352,6 +1352,11 @@ (Nombre sugerido) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 3e0ab156a68..950384c46df 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -1352,6 +1352,11 @@ (Nom suggéré) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 424a8e0310b..ceffffd78c9 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -1352,6 +1352,11 @@ (Nome consigliato) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index d588b1908d7..d9b588fc6aa 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -1352,6 +1352,11 @@ (推奨される名前) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index ec0d939e7b2..bfa7b1f334e 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -1352,6 +1352,11 @@ (제안된 이름) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index ae93051caa0..9a6708209c6 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -1352,6 +1352,11 @@ (Sugerowana nazwa) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 0e0c2367513..e9ed0932ba8 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -1352,6 +1352,11 @@ (Nome sugerido) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index e25503d865e..de3c98a02a2 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -1352,6 +1352,11 @@ (предложенное имя) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index a296c02e44c..81411679f2c 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -1352,6 +1352,11 @@ (Önerilen ad) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index aa66fa326f6..5e448c97391 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -1352,6 +1352,11 @@ (建议名称) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index d8517bff3ff..fdfce2fa627 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -1352,6 +1352,11 @@ (建議的名稱) + + The namespace '{0}' clashes with the type '{1}'. + The namespace '{0}' clashes with the type '{1}'. + + Access modifiers cannot be applied to an SRTP constraint. Access modifiers cannot be applied to an SRTP constraint. @@ -8972,21 +8977,21 @@ This expression is a function value. When used in an interpolated string it will be formatted using its 'ToString' method, which is likely not the intended behavior. Consider applying the function to its arguments. - - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. - - - - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? - - - - emit GetObjectData and field-restoring deserialization constructor for exception types - emit GetObjectData and field-restoring deserialization constructor for exception types - - + + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + '{0}' cannot be the final expression in a computation expression. Finish with 'return', 'return!', or a simple expression. + + + + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + This list expression contains a single tuple element. Did you mean to use ';' instead of ',' to separate list elements? + + + + emit GetObjectData and field-restoring deserialization constructor for exception types + emit GetObjectData and field-restoring deserialization constructor for exception types + + \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs index f989220189e..0968530396a 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs @@ -80,4 +80,33 @@ do printfn "test" |> shouldFail |> withDiagnostics [ (Error 201, Line 4, Col 1, Line 4, Col 18, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") - ] \ No newline at end of file + ] + +[] +let ``Namespace-type collision says type not module (FS3888)`` () = + let source1 = """namespace Ns +type T = { Field: int } +""" + let source2 = "namespace Ns.T" + FSharp source1 + |> withAdditionalSourceFile (FsSourceWithFileName "second.fs" source2) + |> compile + |> shouldFail + |> withErrorCode 3888 + |> withDiagnosticMessageMatches "type" + |> ignore + +[] +let ``Namespace-module collision still says module (FS0247)`` () = + let source1 = """namespace Ns +module M = + let x = 1 +""" + let source2 = "namespace Ns.M" + FSharp source1 + |> withAdditionalSourceFile (FsSourceWithFileName "second.fs" source2) + |> compile + |> shouldFail + |> withErrorCode 0247 + |> withDiagnosticMessageMatches "namespace and a module" + |> ignore \ No newline at end of file From 7f3c50870babd8d00c1227db60c99380c6eea94f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 25 May 2026 11:40:35 +0200 Subject: [PATCH 2/2] Apply remaining changes --- .executor-pid | 1 + src/Compiler/Service/ServiceParsedInputOps.fs | 54 ++++++++++++++++--- 2 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 .executor-pid diff --git a/.executor-pid b/.executor-pid new file mode 100644 index 00000000000..f4cce1bba91 --- /dev/null +++ b/.executor-pid @@ -0,0 +1 @@ +22280 \ No newline at end of file diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index ed1a4da5bf5..35bbe6e884e 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -2602,17 +2602,55 @@ module ParsedInput = mkPos line ctx.Pos.Column + let private tryFindLastHashRLineInScript (parsedInput: ParsedInput) = + if + not ( + parsedInput.FileName.EndsWith(".fsx", System.StringComparison.OrdinalIgnoreCase) + || parsedInput.FileName.EndsWith(".fsscript", System.StringComparison.OrdinalIgnoreCase) + ) + then + None + else + match parsedInput with + | ParsedInput.SigFile _ -> None + | ParsedInput.ImplFile(ParsedImplFileInput(hashDirectives = fileHashes; contents = contents)) -> + let mutable lastLine = 0 + + let consider (ParsedHashDirective(ident, _, r)) = + if ident = "r" && r.EndLine > lastLine then + lastLine <- r.EndLine + + fileHashes |> List.iter consider + + let rec walkDecl (decl: SynModuleDecl) = + match decl with + | SynModuleDecl.HashDirective(hashDirective = hd) -> consider hd + | SynModuleDecl.NestedModule(decls = decls) -> List.iter walkDecl decls + | SynModuleDecl.NamespaceFragment(SynModuleOrNamespace(decls = decls)) -> List.iter walkDecl decls + | _ -> () + + for SynModuleOrNamespace(decls = decls) in contents do + List.iter walkDecl decls + + if lastLine > 0 then Some lastLine else None + let FindNearestPointToInsertOpenDeclaration (currentLine: int) (parsedInput: ParsedInput) (entity: ShortIdents) (insertionPoint: OpenStatementInsertionPoint) = - match tryFindNearestPointAndModules currentLine parsedInput insertionPoint with - | Some(scope, _, point), modules -> findBestPositionToInsertOpenDeclaration modules scope point entity - | _ -> - // we failed to find insertion point because ast is empty for some reason, return top left point in this case - { - ScopeKind = ScopeKind.TopModule - Pos = mkPos 1 0 - } + let ctx = + match tryFindNearestPointAndModules currentLine parsedInput insertionPoint with + | Some(scope, _, point), modules -> findBestPositionToInsertOpenDeclaration modules scope point entity + | _ -> + // we failed to find insertion point because ast is empty for some reason, return top left point in this case + { + ScopeKind = ScopeKind.TopModule + Pos = mkPos 1 0 + } + + // For .fsx scripts, ensure the open is placed after any #r directives. + match tryFindLastHashRLineInScript parsedInput with + | Some lastRLine when ctx.Pos.Line <= lastRLine -> { ctx with Pos = mkPos (lastRLine + 1) 0 } + | _ -> ctx