From 79b1080b7b7d375a4084d391aeee1dbb1e2dcfb7 Mon Sep 17 00:00:00 2001 From: Martin521 <29605222+Martin521@users.noreply.github.com> Date: Wed, 5 Aug 2026 17:08:20 +0000 Subject: [PATCH 1/5] ignore #: directives --- src/Compiler/FSComp.txt | 1 + src/Compiler/lex.fsl | 7 ++++++ .../CompilerDirectives/IgnoreColon.fs | 24 +++++++++++++++++++ .../FSharp.Compiler.ComponentTests.fsproj | 1 + 4 files changed, 33 insertions(+) create mode 100644 tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 26699fa4d9b..27a449bb6c5 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1844,3 +1844,4 @@ featureImprovedImpliedArgumentNamesPartTwo,"Improved implied argument names with 3906,tcRecordExplicitFieldShadowsSpreadField,"Explicit field '%s' shadows a field with the same name from an earlier spread." 3907,tcRecordExprSpreadFieldShadowsSpreadField,"Spread field '%s' shadows a field with the same name from an earlier spread." featureRecordSpreads,"record type and expression spreads" +3908,lexColonDirectiveMustBeFirst,"#: directives must appear as the first non-whitespace characters on a line" diff --git a/src/Compiler/lex.fsl b/src/Compiler/lex.fsl index 32d1a39acde..f4d39a5adfe 100644 --- a/src/Compiler/lex.fsl +++ b/src/Compiler/lex.fsl @@ -754,6 +754,13 @@ rule token (args: LexArgs) (skip: bool) = parse { errorR(Error(FSComp.SR.lexInvalidIdentifier(), lexbuf.LexemeRange)) Keywords.IdentifierToken args lexbuf "" } + | "#:" anystring newline + { let m = lexbuf.LexemeRange + shouldStartLine args lexbuf m (FSComp.SR.lexColonDirectiveMustBeFirst()) + incrLine lexbuf + if not skip then WHITESPACE (LexCont.Token(args.ifdefStack, args.stringNest)) + else token args skip lexbuf } + | ('#' anywhite* | "#line" anywhite+ ) digit+ anywhite* ('@'? "\"" [^'\n''\r''"']+ '"')? anywhite* newline { let pos = lexbuf.EndPos if skip then diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs b/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs new file mode 100644 index 00000000000..de33706bf63 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs @@ -0,0 +1,24 @@ +namespace CompilerDirectives + +open Xunit +open FSharp.Test.Compiler + +module IgnoreColon = + + let source = """ +module test +#:r test.dll +[] +let main _ = + #:source test.fs + 0 +""" + + [] + let ignoreColonDirective () = + + FSharp source + |> compile + |> withDiagnostics [ + Error 3908, Line 6, Col 5, Line 6, Col 22, "#: directives must appear as the first non-whitespace characters on a line" + ] diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 476b903efcf..ba60571ea5b 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -33,6 +33,7 @@ + From fd5cce0092a6c306abad42c5e2bfd8e725e0ad67 Mon Sep 17 00:00:00 2001 From: Martin521 <29605222+Martin521@users.noreply.github.com> Date: Wed, 5 Aug 2026 18:08:50 +0000 Subject: [PATCH 2/5] add release notes --- docs/release-notes/.FSharp.Compiler.Service/11.0.100.md | 1 + docs/release-notes/.Language/11.0.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index 0f816258bbf..cd59cbd8bde 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -161,6 +161,7 @@ * Exception field serialization (`GetObjectData` and field-restoring constructor) is now gated behind `langversion:11` (`LanguageFeature.ExceptionFieldSerializationSupport`). With langversion ≤10, exception codegen is unchanged from pre-#19342 behavior. ([PR #19746](https://github.com/dotnet/fsharp/pull/19746)) * Lower string-typed interpolated strings to `System.String.Concat` rather than the reflection-based `printf` engine, making them trim- and NativeAOT-compatible. This generalizes and ungates the previous all-string `String.Concat` optimization, so it now applies to every string-typed interpolation. ([Language suggestion #1108](https://github.com/fsharp/fslang-suggestions/issues/1108), [PR #19971](https://github.com/dotnet/fsharp/pull/19971)) * Interpolated string holes (e.g. `$"{x}"`) are now formatted with invariant culture (via the `string` operator) instead of the current thread culture. ([PR #19971](https://github.com/dotnet/fsharp/pull/19971)) +* Lines starting with `#:` are now ignored ([Language suggestion 1440](https://github.com/fsharp/fslang-suggestions/issues/1440), [RFC FS-1337](https://github.com/fsharp/fslang-design/pull/830), [PR #20211](https://github.com/dotnet/fsharp/pull/20211)) ### Breaking Changes diff --git a/docs/release-notes/.Language/11.0.md b/docs/release-notes/.Language/11.0.md index 056c3599251..3d59377fa44 100644 --- a/docs/release-notes/.Language/11.0.md +++ b/docs/release-notes/.Language/11.0.md @@ -6,3 +6,5 @@ ### Fixed ### Changed + +* Lines starting with `#:` are now ignored ([Language suggestion 1440](https://github.com/fsharp/fslang-suggestions/issues/1440), [RFC FS-1337](https://github.com/fsharp/fslang-design/pull/830), [PR #20211](https://github.com/dotnet/fsharp/pull/20211)) From 9bf45743d5217a6f15e16f78da461fcbd9d65eb8 Mon Sep 17 00:00:00 2001 From: Martin521 <29605222+Martin521@users.noreply.github.com> Date: Wed, 5 Aug 2026 18:13:50 +0000 Subject: [PATCH 3/5] fix PR # --- docs/release-notes/.FSharp.Compiler.Service/11.0.100.md | 2 +- docs/release-notes/.Language/11.0.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index cd59cbd8bde..507de9f9b68 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -161,7 +161,7 @@ * Exception field serialization (`GetObjectData` and field-restoring constructor) is now gated behind `langversion:11` (`LanguageFeature.ExceptionFieldSerializationSupport`). With langversion ≤10, exception codegen is unchanged from pre-#19342 behavior. ([PR #19746](https://github.com/dotnet/fsharp/pull/19746)) * Lower string-typed interpolated strings to `System.String.Concat` rather than the reflection-based `printf` engine, making them trim- and NativeAOT-compatible. This generalizes and ungates the previous all-string `String.Concat` optimization, so it now applies to every string-typed interpolation. ([Language suggestion #1108](https://github.com/fsharp/fslang-suggestions/issues/1108), [PR #19971](https://github.com/dotnet/fsharp/pull/19971)) * Interpolated string holes (e.g. `$"{x}"`) are now formatted with invariant culture (via the `string` operator) instead of the current thread culture. ([PR #19971](https://github.com/dotnet/fsharp/pull/19971)) -* Lines starting with `#:` are now ignored ([Language suggestion 1440](https://github.com/fsharp/fslang-suggestions/issues/1440), [RFC FS-1337](https://github.com/fsharp/fslang-design/pull/830), [PR #20211](https://github.com/dotnet/fsharp/pull/20211)) +* Lines starting with `#:` are now ignored ([Language suggestion 1440](https://github.com/fsharp/fslang-suggestions/issues/1440), [RFC FS-1337](https://github.com/fsharp/fslang-design/pull/830), [PR #20212](https://github.com/dotnet/fsharp/pull/20212)) ### Breaking Changes diff --git a/docs/release-notes/.Language/11.0.md b/docs/release-notes/.Language/11.0.md index 3d59377fa44..7c86052a7a6 100644 --- a/docs/release-notes/.Language/11.0.md +++ b/docs/release-notes/.Language/11.0.md @@ -7,4 +7,4 @@ ### Changed -* Lines starting with `#:` are now ignored ([Language suggestion 1440](https://github.com/fsharp/fslang-suggestions/issues/1440), [RFC FS-1337](https://github.com/fsharp/fslang-design/pull/830), [PR #20211](https://github.com/dotnet/fsharp/pull/20211)) +* Lines starting with `#:` are now ignored ([Language suggestion 1440](https://github.com/fsharp/fslang-suggestions/issues/1440), [RFC FS-1337](https://github.com/fsharp/fslang-design/pull/830), [PR #20212](https://github.com/dotnet/fsharp/pull/20212)) From 417605380614ea126be968d6ec38bd661da08528 Mon Sep 17 00:00:00 2001 From: Martin521 <29605222+Martin521@users.noreply.github.com> Date: Wed, 5 Aug 2026 18:47:46 +0000 Subject: [PATCH 4/5] Xlf Update --- 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 +++++ 13 files changed, 65 insertions(+) diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 8cb70b4c49e..012bc3f2b1f 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -872,6 +872,11 @@ Bajtový řetězec se nedá interpolovat. + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. Rozšířená interpolace řetězců není v této verzi jazyka F# podporována. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 5686312be6b..2f3b8d23ccd 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -872,6 +872,11 @@ Eine Bytezeichenfolge darf nicht interpoliert werden. + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. Die erweiterte Zeichenfolgeninterpolation wird in dieser Version von F# nicht unterstützt. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index a3b4cfce50b..1a7e1958a5d 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -872,6 +872,11 @@ no se puede interpolar una cadena de bytes + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. No se admite la interpolación de cadenas extendida en esta versión de F#. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index bf46f5ee12b..2630db77844 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -872,6 +872,11 @@ une chaîne d'octets ne peut pas être interpolée + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. L'interpolation de chaîne étendue n'est pas prise en charge dans cette version de F#. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 6d705cdc2d1..e3d7c86042b 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -872,6 +872,11 @@ non è possibile interpolare una stringa di byte + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. L'interpolazione di stringa estesa non è supportata in questa versione di F#. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 0b35b8e6dac..7c9bbb147ad 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -872,6 +872,11 @@ バイト文字列は補間されていない可能性があります + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. 拡張文字列補間は、このバージョンの F# ではサポートされていません。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index b00f54bfa76..8f07c36c918 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -872,6 +872,11 @@ 바이트 문자열을 보간하지 못할 수 있습니다. + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. 확장 문자열 보간은 이 버전의 F#에서 지원되지 않습니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index b6d4b78a2d8..958d230458e 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -872,6 +872,11 @@ ciąg bajtowy nie może być interpolowany + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. Rozszerzona interpolacja ciągów nie jest obsługiwana w tej wersji języka F#. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index ba46752a529..0c7452b6041 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -872,6 +872,11 @@ uma cadeia de caracteres de byte não pode ser interpolada + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. Não há suporte para interpolação de cadeia de caracteres estendida nesta versão do F#. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 4a13225bc33..96e88facd2a 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -872,6 +872,11 @@ невозможно выполнить интерполяцию для строки байтов + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. Расширенная интерполяция строк не поддерживается в этой версии F#. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 0d880a3f23a..304bc5669ee 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -872,6 +872,11 @@ bir bayt dizesi, düz metin arasına kod eklenerek kullanılamaz + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. Genişletilmiş dize ilişkilendirmesi bu F# sürümünde desteklenmiyor. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index ce2c173e893..198d8cfee32 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -872,6 +872,11 @@ 不能内插字节字符串 + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. 此版本的 F# 不支持扩展字符串内插。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 09d5f37bea9..fd97d5b5485 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -872,6 +872,11 @@ 位元組字串不能是插補字串 + + #: directives must appear as the first non-whitespace characters on a line + #: directives must appear as the first non-whitespace characters on a line + + Extended string interpolation is not supported in this version of F#. 此 F# 版本不支援擴充字串插補。 From bbc84fff61283a67c4e6da36415734595d9031b8 Mon Sep 17 00:00:00 2001 From: Martin521 <29605222+Martin521@users.noreply.github.com> Date: Wed, 5 Aug 2026 20:03:52 +0000 Subject: [PATCH 5/5] deal with windows line ends --- .../CompilerDirectives/IgnoreColon.fs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs b/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs index de33706bf63..78b53015441 100644 --- a/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs +++ b/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs @@ -19,6 +19,4 @@ let main _ = FSharp source |> compile - |> withDiagnostics [ - Error 3908, Line 6, Col 5, Line 6, Col 22, "#: directives must appear as the first non-whitespace characters on a line" - ] + |> withDiagnosticMessage "#: directives must appear as the first non-whitespace characters on a line" \ No newline at end of file