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 608978809b3..1d338a2f530 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -167,6 +167,7 @@ * 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)) * Stabilized several `preview` language features into F# 11.0 (`--langversion:11.0`, enabled by default with a .NET 11 SDK): `MethodOverloadsCache`, `ErrorOnMissingSignatureAttribute`, `DirectDelegateConstruction`, `AccessProtectedBaseFieldFromClosure`, and `RecordSpreads`. `FromEndSlicing` intentionally remains in `preview`. ([PR #20199](https://github.com/dotnet/fsharp/pull/20199)) * 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 #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 8c7f9ab94d6..07752bcd79f 100644 --- a/docs/release-notes/.Language/11.0.md +++ b/docs/release-notes/.Language/11.0.md @@ -14,6 +14,7 @@ ### 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 #20212](https://github.com/dotnet/fsharp/pull/20212)) * Direct delegate construction ([PR #19993](https://github.com/dotnet/fsharp/pull/19993)) * A delegate built from a method or function now points straight at that method instead of an intermediate closure, so `delegate.Method` is the real target and no closure class is generated. * Two delegates built from the same method and target now compare equal, where the previous closure form produced distinct instances; this also makes `Delegate.Remove` (and `-=` on events) match and remove such a delegate that it previously left in place. diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index e446192d1a6..e0d961668ef 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1846,3 +1846,4 @@ featureImprovedImpliedArgumentNamesPartTwo,"Improved implied argument names with featureRecordSpreads,"record type and expression spreads" 3908,xmlDocIncludeError,"XML documentation include error: %s" 3908,xmlDocIncludeError2,"XML documentation include error: Unable to include XML fragment '%s' of file '%s' -- %s" +3909,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/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 23610d7c528..9b29eded5bf 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 62e00ba9863..3118e9dc023 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 1ebf9e2a654..6376c7500f0 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 4cac43340b4..e32fe3400e1 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 51164029d1a..9b4e2db0255 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 ec4b067e85b..321c9aa1e06 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 67cacd877d5..2943abd9a4c 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 45059c8802f..92ae82f16aa 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 2b06a5553dd..f84b166032a 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 7f626e9888f..da12f5cd542 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 ca5be2359f2..b3d927dfb66 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 13b1b98ba84..582848782a5 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 4b66108b372..769df31e9d3 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# 版本不支援擴充字串插補。 diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs b/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs new file mode 100644 index 00000000000..78b53015441 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerDirectives/IgnoreColon.fs @@ -0,0 +1,22 @@ +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 + |> withDiagnosticMessage "#: directives must appear as the first non-whitespace characters on a line" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 8057ebb1da8..d6f7886d85e 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -33,6 +33,7 @@ +