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 ab65df29a6e..977c47bec1a 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -169,6 +169,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 04c6b1a7d33..48af3e625f7 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1845,3 +1845,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 start at the beginning of a line" diff --git a/src/Compiler/lex.fsl b/src/Compiler/lex.fsl index 32d1a39acde..ac73fd06961 100644 --- a/src/Compiler/lex.fsl +++ b/src/Compiler/lex.fsl @@ -754,6 +754,12 @@ rule token (args: LexArgs) (skip: bool) = parse { errorR(Error(FSComp.SR.lexInvalidIdentifier(), lexbuf.LexemeRange)) Keywords.IdentifierToken args lexbuf "" } + | "#:" anystring + { let m = lexbuf.LexemeRange + shouldStartLine args lexbuf m (FSComp.SR.lexColonDirectiveMustBeFirst()) + if not skip then WHITESPACE (LexCont.Token(args.ifdefStack, args.stringNest)) + else endline LexerEndlineContinuation.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 e007c5655fa..6968bc66100 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -867,6 +867,11 @@ Bajtový řetězec se nedá interpolovat. + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 002c068e7fb..928dceb4a15 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -867,6 +867,11 @@ Eine Bytezeichenfolge darf nicht interpoliert werden. + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 865897420f3..bb71775e90a 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -867,6 +867,11 @@ no se puede interpolar una cadena de bytes + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 5bf1a9add86..a25bf43f909 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -867,6 +867,11 @@ une chaîne d'octets ne peut pas être interpolée + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 7099e8b391b..57c10a40a76 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -867,6 +867,11 @@ non è possibile interpolare una stringa di byte + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 b8e4d9b7503..0ea2e3a57f6 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -867,6 +867,11 @@ バイト文字列は補間されていない可能性があります + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 04533426fc5..fdb7398647a 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -867,6 +867,11 @@ 바이트 문자열을 보간하지 못할 수 있습니다. + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 abaf87acfbf..04c219d24ac 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -867,6 +867,11 @@ ciąg bajtowy nie może być interpolowany + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 963037d4a72..c41341a9fda 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -867,6 +867,11 @@ uma cadeia de caracteres de byte não pode ser interpolada + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 53ea084423b..b24f781f1cf 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -867,6 +867,11 @@ невозможно выполнить интерполяцию для строки байтов + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 4540639f47c..edfc62090d4 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -867,6 +867,11 @@ bir bayt dizesi, düz metin arasına kod eklenerek kullanılamaz + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 76969b500eb..06ed554577c 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -867,6 +867,11 @@ 不能内插字节字符串 + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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 1c1ffb1b333..076bf17ac73 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -867,6 +867,11 @@ 位元組字串不能是插補字串 + + #: directives must start at the beginning of a line + #: directives must start at the beginning of 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..dbfac03f200 --- /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 +#:ignore also at eof""" + + [] + let ignoreColonDirective () = + + FSharp source + |> compile + |> withDiagnostics [ + Error 3909, Line 6, Col 5, Line 6, Col 21, "#: directives must start at the beginning of 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 @@ +