diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md index 3d4b290dfd9..da54c8b8802 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md @@ -11,6 +11,7 @@ * Nullness export - make sure option<> and other UseNullAsTrueValue types are properly annotated as nullable for C# and reflection consumers [PR #17528](https://github.com/dotnet/fsharp/pull/17528) * MethodAccessException on equality comparison of a type private to module. ([Issue #17541](https://github.com/dotnet/fsharp/issues/17541), [PR #17548](https://github.com/dotnet/fsharp/pull/17548)) * Fixed checking failure when `global` namespace is involved with enabled GraphBasedChecking ([PR #17553](https://github.com/dotnet/fsharp/pull/17553)) +* Add missing byte chars notations, enforce limits in decimal notation in byte char & string (Issues [#15867](https://github.com/dotnet/fsharp/issues/15867), [#15868](https://github.com/dotnet/fsharp/issues/15868), [#15869](https://github.com/dotnet/fsharp/issues/15869), [PR #15898](https://github.com/dotnet/fsharp/pull/15898)) ### Added diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index e452d21f100..8d5475e8326 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1020,7 +1020,7 @@ lexfltSeparatorTokensOfPatternMatchMisaligned,"The '|' tokens separating rules o # ----------------------------------------------------------------------------- lexCharNotAllowedInOperatorNames,"'%s' is not permitted as a character in operator names and is reserved for future use" lexUnexpectedChar,"Unexpected character '%s'" -1140,lexByteArrayCannotEncode,"This byte array literal contains characters that do not encode as a single byte" +1140,lexByteArrayCannotEncode,"This byte array literal contains %d characters that do not encode as a single byte" 1141,lexIdentEndInMarkReserved,"Identifiers followed by '%s' are reserved for future use" 1142,lexOutsideEightBitSigned,"This number is outside the allowable range for 8-bit signed integers" 1143,lexOutsideEightBitSignedHex,"This number is outside the allowable range for hexadecimal 8-bit signed integers" @@ -1037,7 +1037,8 @@ lexUnexpectedChar,"Unexpected character '%s'" 1154,lexOutsideDecimal,"This number is outside the allowable range for decimal literals" 1155,lexOutsideThirtyTwoBitFloat,"This number is outside the allowable range for 32-bit floats" 1156,lexInvalidNumericLiteral,"This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1.0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1I (bigint)." -1157,lexInvalidByteLiteral,"This is not a valid byte literal" +1157,lexInvalidAsciiByteLiteral,"This is not a valid byte character literal. The value must be less than or equal to '\127'B." +1157,lexInvalidTrigraphAsciiByteLiteral,"This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error." 1158,lexInvalidCharLiteral,"This is not a valid character literal" 1159,lexThisUnicodeOnlyInStringLiterals,"This Unicode encoding is only valid in string literals" 1160,lexTokenReserved,"This token is reserved for future use" @@ -1131,6 +1132,8 @@ lexIfOCaml,"IF-FSHARP/IF-CAML regions are no longer supported" 1249,lexUnmatchedRBracesInTripleQuote,"The interpolated string contains unmatched closing braces." 1250,lexTooManyPercentsInTripleQuote,"The interpolated triple quoted string literal does not start with enough '$' characters to allow this many consecutive '%%' characters." 1251,lexExtendedStringInterpolationNotSupported,"Extended string interpolation is not supported in this version of F#." +1252,lexInvalidCharLiteralInString,"'%s' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '%s'. In a future F# version this warning will be promoted to an error." +1253,lexByteArrayOutisdeAscii,"This byte array literal contains %d non-ASCII characters. All characters should be < 128y." # reshapedmsbuild.fs 1300,toolLocationHelperUnsupportedFrameworkVersion,"The specified .NET Framework version '%s' is not supported. Please specify a value from the enumeration Microsoft.Build.Utilities.TargetDotNetFrameworkVersion." # ----------------------------------------------------------------------------- diff --git a/src/Compiler/SyntaxTree/LexHelpers.fs b/src/Compiler/SyntaxTree/LexHelpers.fs index 8bcae32d782..736e4be04f5 100644 --- a/src/Compiler/SyntaxTree/LexHelpers.fs +++ b/src/Compiler/SyntaxTree/LexHelpers.fs @@ -222,16 +222,32 @@ let addUnicodeChar buf c = addIntChar buf (int c) let addByteChar buf (c: char) = addIntChar buf (int32 c % 256) +type LargerThanOneByte = int +type LargerThan127ButInsideByte = int + /// Sanity check that high bytes are zeros. Further check each low byte <= 127 -let stringBufferIsBytes (buf: ByteBuffer) = +let errorsInByteStringBuffer (buf: ByteBuffer) = let bytes = buf.AsMemory() - let mutable ok = true + assert (bytes.Length % 2 = 0) + + // Enhancement?: return faulty values? + // But issue: we don't know range of values -> no direct mapping from value to range & notation + + // values with high byte <> 0 + let mutable largerThanOneByteCount = 0 + // values with high byte = 0, but low byte > 127 + let mutable largerThan127ButSingleByteCount = 0 for i = 0 to bytes.Length / 2 - 1 do if bytes.Span[i * 2 + 1] <> 0uy then - ok <- false + largerThanOneByteCount <- largerThanOneByteCount + 1 + elif bytes.Span[i * 2] > 127uy then + largerThan127ButSingleByteCount <- largerThan127ButSingleByteCount + 1 - ok + if largerThanOneByteCount + largerThan127ButSingleByteCount > 0 then + Some(largerThanOneByteCount, largerThan127ButSingleByteCount) + else + None let newline (lexbuf: LexBuffer<_>) = lexbuf.EndPos <- lexbuf.EndPos.NextLine diff --git a/src/Compiler/SyntaxTree/LexHelpers.fsi b/src/Compiler/SyntaxTree/LexHelpers.fsi index 616bfa8a6fd..0ba901a05e0 100644 --- a/src/Compiler/SyntaxTree/LexHelpers.fsi +++ b/src/Compiler/SyntaxTree/LexHelpers.fsi @@ -97,7 +97,9 @@ val stringBufferAsString: ByteBuffer -> string val stringBufferAsBytes: ByteBuffer -> byte[] -val stringBufferIsBytes: ByteBuffer -> bool +type LargerThanOneByte = int +type LargerThan127ButInsideByte = int +val errorsInByteStringBuffer: ByteBuffer -> Option val newline: Lexing.LexBuffer<'a> -> unit diff --git a/src/Compiler/lex.fsl b/src/Compiler/lex.fsl index cd73aa454c2..fd95cd3ebce 100644 --- a/src/Compiler/lex.fsl +++ b/src/Compiler/lex.fsl @@ -137,10 +137,14 @@ let startString args (lexbuf: UnicodeLexing.Lexbuf) = if kind.IsInterpolated then fail args lexbuf (FSComp.SR.lexByteStringMayNotBeInterpolated()) () BYTEARRAY (Lexhelp.stringBufferAsBytes buf, synByteStringKind, cont) - elif Lexhelp.stringBufferIsBytes buf then - BYTEARRAY (Lexhelp.stringBufferAsBytes buf, synByteStringKind, cont) else - fail args lexbuf (FSComp.SR.lexByteArrayCannotEncode()) () + match Lexhelp.errorsInByteStringBuffer buf with + | Some (largerThanOneByte, largerThan127) -> + if largerThanOneByte > 0 then + fail args lexbuf (FSComp.SR.lexByteArrayCannotEncode(largerThanOneByte)) () + if largerThan127 > 0 then + warning (Error(FSComp.SR.lexByteArrayOutisdeAscii(largerThan127), lexbuf.LexemeRange)) + | None -> () BYTEARRAY (Lexhelp.stringBufferAsBytes buf, synByteStringKind, cont) elif kind.IsInterpolated then let s = Lexhelp.stringBufferAsString buf @@ -518,7 +522,7 @@ rule token (args: LexArgs) (skip: bool) = parse { let s = lexeme lexbuf let x = int32 (if s.[1] = '\\' then escape s.[2] else s.[1]) if x < 0 || x > 127 then - fail args lexbuf (FSComp.SR.lexInvalidByteLiteral()) (UINT8(byte 0)) + fail args lexbuf (FSComp.SR.lexInvalidAsciiByteLiteral()) (UINT8(byte 0)) else UINT8 (byte(x)) } @@ -535,26 +539,50 @@ rule token (args: LexArgs) (skip: bool) = parse { let s = lexeme lexbuf let x = int32 (trigraph s.[2] s.[3] s.[4]) if x < 0 || x > 255 then - fail args lexbuf (FSComp.SR.lexInvalidByteLiteral()) (UINT8(byte 0)) + fail args lexbuf (FSComp.SR.lexInvalidAsciiByteLiteral()) (UINT8(byte 0)) + elif x > 127 then + // TODO: Promote to Error: + // * Adjust range check in `if` above to `x > 127` + // * Remove this `elif` expression + // * Remove `lexInvalidTrigraphAsciiByteLiteral` from `FSComp.txt` + warning (Error(FSComp.SR.lexInvalidTrigraphAsciiByteLiteral(), lexbuf.LexemeRange)) + UINT8 (byte(x)) else UINT8 (byte(x)) } + | '\'' unicodeGraphShort '\'' { CHAR (char (int32 (unicodeGraphShort (lexemeTrimBoth lexbuf 3 1)))) } + | '\'' unicodeGraphShort '\'' 'B' { let x = int32 (unicodeGraphShort (lexemeTrimBoth lexbuf 3 2)) if x < 0 || x > 127 then - fail args lexbuf (FSComp.SR.lexInvalidByteLiteral()) (UINT8(byte 0)) + fail args lexbuf (FSComp.SR.lexInvalidAsciiByteLiteral()) (UINT8(byte 0)) else UINT8 (byte(x)) } | '\'' hexGraphShort '\'' { CHAR (char (int32 (hexGraphShort (lexemeTrimBoth lexbuf 3 1)))) } - | '\'' unicodeGraphShort '\'' { CHAR (char (int32 (unicodeGraphShort (lexemeTrimBoth lexbuf 3 1)))) } + | '\'' hexGraphShort '\'' 'B' + { let x = int32 (hexGraphShort (lexemeTrimBoth lexbuf 3 2)) + if x < 0 || x > 127 then + fail args lexbuf (FSComp.SR.lexInvalidAsciiByteLiteral()) (UINT8(byte 0)) + else + UINT8 (byte(x)) } | '\'' unicodeGraphLong '\'' { match unicodeGraphLong (lexemeTrimBoth lexbuf 3 1) with | SingleChar(c) -> CHAR (char c) | _ -> fail args lexbuf (FSComp.SR.lexThisUnicodeOnlyInStringLiterals()) (CHAR (char 0)) } + | '\'' unicodeGraphLong '\'' 'B' + { match unicodeGraphLong (lexemeTrimBoth lexbuf 3 2) with + | SingleChar(c) -> + let x = int32 c + if x < 0 || x > 127 then + fail args lexbuf (FSComp.SR.lexInvalidAsciiByteLiteral()) (UINT8(byte 0)) + else + UINT8 (byte(x)) + | _ -> fail args lexbuf (FSComp.SR.lexInvalidAsciiByteLiteral()) (UINT8(byte 0)) } + | "(*IF-FSHARP" { if lexbuf.SupportsFeature LanguageFeature.MLCompatRevisions then mlCompatWarning (FSComp.SR.lexIndentOffForML()) lexbuf.LexemeRange @@ -1201,11 +1229,26 @@ and singleQuoteString (sargs: LexerStringArgs) (skip: bool) = parse | trigraph { let (buf, _fin, m, kind, args) = sargs let s = lexeme lexbuf - addByteChar buf (trigraph s.[1] s.[2] s.[3]) - if not skip then - STRING_TEXT (LexCont.String(args.ifdefStack, args.stringNest, LexerStringStyle.SingleQuote, kind, args.interpolationDelimiterLength, m)) + let result() = + if not skip then + STRING_TEXT (LexCont.String(args.ifdefStack, args.stringNest, LexerStringStyle.SingleQuote, kind, args.interpolationDelimiterLength, m)) + else + singleQuoteString sargs skip lexbuf + let c = trigraph s.[1] s.[2] s.[3] + let x = int c + if x < 0 || x > 255 then + // TODO: Promote to Error: + // * remove `addByteChar ...` + // * remove `warning ...` + // * Adjust `lexInvalidCharLiteralInString` in `FSComp.txt`: remove `Note` (incl. 2nd placeholder) + // * uncomment `fail ...` + addByteChar buf c + warning (Error(FSComp.SR.lexInvalidCharLiteralInString (s[0..3], sprintf "\\%03i" (x % 256)), lexbuf.LexemeRange)) + //fail args lexbuf (FSComp.SR.lexInvalidCharLiteralInString (s[0..3])) () + result() else - singleQuoteString sargs skip lexbuf } + addByteChar buf c + result() } | hexGraphShort { let (buf, _fin, m, kind, args) = sargs @@ -1233,7 +1276,8 @@ and singleQuoteString (sargs: LexerStringArgs) (skip: bool) = parse singleQuoteString sargs skip lexbuf match unicodeGraphLong hexChars with | Invalid -> - fail args lexbuf (FSComp.SR.lexInvalidUnicodeLiteral hexChars) (result()) + fail args lexbuf (FSComp.SR.lexInvalidUnicodeLiteral hexChars) () + result() | SingleChar(c) -> addUnicodeChar buf (int c) result() diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index d00017d2697..2bfc476c15d 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -737,6 +737,11 @@ Používá se ve výpočtových výrazech pro zavedení konstrukce smyčky, kde podmínka je výsledkem jiného výpočtového výrazu. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated Bajtový řetězec se nedá interpolovat. @@ -752,11 +757,26 @@ Oblasti IF-FSHARP/IF-CAML už nejsou podporovány. + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier Toto není platný identifikátor + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. Znak }} musí být v interpolovaném řetězci uvozený (zdvojeným znakem). @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Tento literál bajtového pole obsahuje znaky, které se nekódují jako jednobajtové. + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ Toto není platný číselný literál. Platné číselné literály zahrnují hodnoty 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1.0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1I (bigint). - - This is not a valid byte literal - Toto není platný bajtový literál. - - This is not a valid character literal Toto není platný znakový literál. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 2bf293d961c..5bd33d9c781 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -737,6 +737,11 @@ Wird in Berechnungsausdrücken zum Bereitstellen eines Schleifenkonstrukts verwendet, bei dem die Bedingung das Ergebnis eines anderen Berechnungsausdrucks ist. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated Eine Bytezeichenfolge darf nicht interpoliert werden. @@ -752,11 +757,26 @@ IF-FSHARP-/IF-CAML-Regionen werden nicht mehr unterstützt + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier Dies ist kein gültiger Bezeichner. + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. Ein }}-Zeichen muss in einer interpolierten Zeichenfolge (durch Verdoppeln) mit Escapezeichen versehen werden. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Dieses Bytearrayliteral enthält Zeichen, die sich nicht als einzelnes Byte codieren lassen. + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ Dies ist kein gültiges numerisches Literal. Unter anderem sind die folgenden numerischen Literale gültig: 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1.0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1I (bigint). - - This is not a valid byte literal - Dies ist kein gültiges Byteliteral. - - This is not a valid character literal Dies ist kein gültiges Zeichenliteral. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 6923afa068f..6be2592f951 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -737,6 +737,11 @@ Se usa en expresiones de cálculo para introducir una construcción de bucle donde la condición es el resultado de otra expresión de cálculo. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated no se puede interpolar una cadena de bytes @@ -752,11 +757,26 @@ Ya no se admiten las regiones IF-FSHARP/IF-CAML + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier Este nombre no es un identificador válido. + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. El carácter "}}" se debe escapar (duplicándose) en las cadenas interpoladas. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Este literal de matriz de bytes contiene caracteres que no se codifican como un solo byte. + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ Este literal numérico no es válido. Entre los literales numéricos válidos se incluyen 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1.0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1I (bigint). - - This is not a valid byte literal - Este no es un literal de byte válido. - - This is not a valid character literal Este no es un literal de carácter válido. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 4207041ad15..a303ecef168 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -737,6 +737,11 @@ Utilisé dans les expressions de calcul pour introduire une construction en boucle où la condition est le résultat d'une autre expression de calcul. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated une chaîne d'octets ne peut pas être interpolée @@ -752,11 +757,26 @@ Les régions IF-FSHARP/IF-CAML ne sont plus prises en charge. + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier Ceci n'est pas un identifiant valide + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. Un caractère '}}' doit faire l'objet d'une séquence d'échappement (par doublement) dans une chaîne interpolée. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Ce littéral de tableau d'octets contient des caractères qui ne sont pas encodés sous forme d'octet unique + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ Il ne s’agit pas d’un littéral numérique valide. Les littéraux numériques valides incluent 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1,0 (float/double), 1,0f (float32/single), 1,0 m (décimal), 1I (bigint). - - This is not a valid byte literal - Littéral d'octet non valide - - This is not a valid character literal Littéral de caractère non valide diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 9c2171b9217..cd2d35cdb15 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -737,6 +737,11 @@ Usato nelle espressioni di calcolo per introdurre un costrutto con riprodurre a ciclo continuo in cui la condizione è il risultato di un'altra espressione di calcolo. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated non è possibile interpolare una stringa di byte @@ -752,11 +757,26 @@ Le aree IF-FSHARP/IF-CAML non sono più supportate + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier Non si tratta di un identificatore valido. + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. In una stringa interpolata è necessario specificare il carattere di escape di un carattere '}}' raddoppiandolo. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Questo valore letterale della matrice di byte contiene caratteri non codificabili come singoli byte + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ Non è un valore letterale numerico valido. I valori letterali numerici validi includono 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint 32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1,0 (float/double), 1,0f (float32/single), 1,0m (decimale), 1I (bigint). - - This is not a valid byte literal - Valore letterale byte non valido - - This is not a valid character literal Valore letterale carattere non valido diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 3ac536db2b4..fed4bf3e349 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -737,6 +737,11 @@ 条件が別の計算式の結果であるループ構造を導入するために、計算式で使用されます。 + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated バイト文字列は補間されていない可能性があります @@ -752,11 +757,26 @@ IF-FSHARP/IF-CAML リージョンは現在サポートされていません + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier これは有効な識別子ではありません + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. 文字 '}}' は、補間された文字列内で (二重にすることで) エスケープする必要があります。 @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - このバイト配列リテラルには、シングル バイトとしてエンコードされない文字が含まれます + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ これは有効な数値リテラルではありません。有効な数値リテラルには、1、0x1、0o1、 0b1、1l (int/int32)、1u (uint/uint32)、1L (int64)、1UL (uint64)、1s (int16)、1us (uint16)、1y (int8/sbyte)、1uy (uint8/byte)、1.0 (float/double)、1.0f (float32/single)、1.0m (10 進)、1I (bigint)。 - - This is not a valid byte literal - これは有効なバイト リテラルではありません - - This is not a valid character literal これは有効な文字リテラルではありません diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 41047438142..9c2609d6e32 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -737,6 +737,11 @@ 계산 식에서 조건이 다른 계산 식의 결과인 루프 구문을 도입하는 데 사용됩니다. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated 바이트 문자열을 보간하지 못할 수 있습니다. @@ -752,11 +757,26 @@ IF-FSHARP/IF-CAML 영역은 더 이상 지원되지 않습니다. + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier 유효한 식별자가 아닙니다. + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. '}}' 문자는 보간된 문자열에서 이중으로 사용하여 이스케이프해야 합니다. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - 이 바이트 배열 리터럴에는 단일 바이트로 인코딩되지 않는 문자가 포함되어 있습니다. + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ 유효한 숫자 리터럴이 아닙니다. 유효한 숫자 리터럴은 1, 0x1, 0o1, 0b1, 1l(int/int32), 1u(uint/uint32), 1L(int64), 1UL(uint64), 1s(int16), 1us(uint16), 1y(int8/)입니다. sbyte), 1uy(uint8/byte), 1.0(float/double), 1.0f(float32/single), 1.0m(decimal), 1I(bigint). - - This is not a valid byte literal - 올바른 바이트 리터럴이 아닙니다. - - This is not a valid character literal 올바른 문자 리터럴이 아닙니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 9e64dbf33d8..47663814082 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -737,6 +737,11 @@ Używane w wyrażeniach obliczeń w celu wprowadzenia konstrukcji pętli, w której warunek jest wynikiem innego wyrażenia obliczeń. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated ciąg bajtowy nie może być interpolowany @@ -752,11 +757,26 @@ Regiony IF-FSHARP/IF-CAML nie są już obsługiwane + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier To nie jest prawidłowy identyfikator + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. W przypadku znaku „}}” należy zastosować ucieczkę (przez wpisanie dwóch takich znaków) w ciągu interpolowanym. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Ten literał tablicy bajtowej zawiera znaki, które nie są kodowane jako pojedynczy bajt + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ To nie jest prawidłowy literał liczbowy. Prawidłowe literały liczbowe to 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/bajt), 1,0 (float/double), 1,0f (float32/single), 1,0 m (dziesiętny), 1I (bigint). - - This is not a valid byte literal - Nie jest to prawidłowy literał bajtowy - - This is not a valid character literal Nie jest to prawidłowy literał znakowy diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 59330e37600..dc8c1670145 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -737,6 +737,11 @@ Usado em expressões de computação para introduzir um constructo de looping em que a condição é o resultado de outra expressão de computação. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated uma cadeia de caracteres de byte não pode ser interpolada @@ -752,11 +757,26 @@ As regiões IF-FSHARP/IF-CAML não são mais suportadas + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier Este não é um identificador válido + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. Um caractere ''}}' precisa ser de escape (ao duplicar) em uma cadeia de caracteres interpolada. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Este literal matriz de byte contém caracteres não codificados como um byte simples + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ Este não é um literal numérico válido. Os literais numéricos válidos incluem 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/ sbyte), 1uy (uint8/byte), 1.0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1I (bigint). - - This is not a valid byte literal - Este não é um literal de byte válido - - This is not a valid character literal Este não é um literal de caractere válido diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 71995741697..a19c0238a73 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -737,6 +737,11 @@ Используется в вычислительных выражениях для введения циклической конструкции, в которой условие является результатом другого вычислительного выражения. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated невозможно выполнить интерполяцию для строки байтов @@ -752,11 +757,26 @@ Регионы IF-FSHARP/IF-CAML больше не поддерживаются + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier Это недопустимый идентификатор + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. Символ "}}" необходимо экранировать (путем дублирования) в интерполированной строке. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Этот литерал массива байтов содержит знаки, не поддерживающие однобайтовую кодировку + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ Это значение не является допустимым числовым литералом. Допустимые числовые литералы: 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1,0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1I (bigint). - - This is not a valid byte literal - Не является допустимым байтовым литералом. - - This is not a valid character literal Не является допустимым символьным литералом. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 4d6a7456a03..084de00eaf6 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -737,6 +737,11 @@ Hesaplama ifadelerinde, koşulun başka bir hesaplama ifadesinin sonucu olduğu bir döngü yapısı eklemek için kullanılır. + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated bir bayt dizesi, düz metin arasına kod eklenerek kullanılamaz @@ -752,11 +757,26 @@ IF-FSHARP/IF-CAML bölgeleri artık desteklenmiyor + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier Bu, geçerli bir tanımlayıcı değil + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. Bir '}}' karakteri, düz metin arasına kod eklenmiş bir dizede kaçış dizisi ile (yineleme yapılarak) belirtilir. @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - Bu bayt dizisi sabit değeri tek bayt olarak kodlanmayan karakterler içeriyor + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ Bu, geçerli bir sayısal değişmez değer değil. Geçerli sayısal değişmez değerler şunları içerir: 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1.0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1I (bigint). - - This is not a valid byte literal - Bu geçerli bir bayt sabit değeri değil - - This is not a valid character literal Bu geçerli bir karakter sabit değeri değil diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 6d942aa6526..b57d440ed73 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -737,6 +737,11 @@ 在计算表达式中用于引入循环构造,其中条件是另一个计算表达式的结果。 + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated 不能内插字节字符串 @@ -752,11 +757,26 @@ 不再支持 IF-FSHARP/IF-CAML 区域 + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier 这不是有效的标识符 + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. 在内插字符串中,必需对 "}}" 字符进行转义(通过加倍)。 @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - 此字节数组文本包含不会以单字节形式进行编码的字符 + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ 这不是有效的数值文本。有效数值包括 1、0x1、0o1、0b1、1l (int/int32)、1u (uint/uint32)、1L (int64)、1UL (uint64)、1s (int16)、1us (uint16)、1y (int8/sbyte)、1uy (uint8/byte)、1.0 (float/double)、1.0f (float32/single)、1.0m (decimal)、1I (bigint)。 - - This is not a valid byte literal - 这不是有效的字节文本 - - This is not a valid character literal 这不是有效的字符文本 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index fa8f6a00187..58baa95a307 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -737,6 +737,11 @@ 用於計算運算式中,以引進迴圈建構,其中條件是另一個計算運算式的結果。 + + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + This byte array literal contains {0} non-ASCII characters. All characters should be < 128y. + + a byte string may not be interpolated 位元組字串不能是插補字串 @@ -752,11 +757,26 @@ 不再支援 IF-FSHARP/IF-CAML 區域 + + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + This is not a valid byte character literal. The value must be less than or equal to '\127'B. + + + + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + '{0}' is not a valid character literal.\nNote: Currently the value is wrapped around byte range to '{1}'. In a future F# version this warning will be promoted to an error. + + This is not a valid identifier 這不是有效的識別項 + + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + This is not a valid byte character literal. The value must be less than or equal to '\127'B.\nNote: In a future F# version this warning will be promoted to an error. + + A '}}' character must be escaped (by doubling) in an interpolated string. 在插補字串中,必須將 '}}' 字元逸出 (重複一次)。 @@ -6483,8 +6503,8 @@ - This byte array literal contains characters that do not encode as a single byte - 這個位元組陣列常值包含不會編碼成單一位元組的字元 + This byte array literal contains {0} characters that do not encode as a single byte + This byte array literal contains {0} characters that do not encode as a single byte @@ -6567,11 +6587,6 @@ 這不是有效的數值常值。有效的數值常值包括 1, 0x1、0o1、0b1、1l (int/int32)、1u (uint/uint32)、1L (int64)、1UL (uint64)、1s (int16)、1us (uint16)、1y (int8/sbyte)、1uy (uint8/byte)、1.0 (float/double)、1.0f (float32/single)、1.0m (decimal)、1I (bigint)。 - - This is not a valid byte literal - 這不是有效的位元組常值 - - This is not a valid character literal 這不是有效的字元常值 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/ByteStrings.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/ByteStrings.fs new file mode 100644 index 00000000000..b3469959680 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/ByteStrings.fs @@ -0,0 +1,133 @@ +module Conformance.LexicalAnalysis.ByteStrings + +open Xunit +open FSharp.Test.Compiler + +/// `'%s' is not a valid character literal.` with note about wrapped value and error soon +let private invalidCharWarningMsg value wrapped = + FSComp.SR.lexInvalidCharLiteralInString (value, wrapped) + |> snd + +/// `This byte array literal contains %d characters that do not encode as a single byte` +let private invalidTwoByteErrorMsg count = + FSComp.SR.lexByteArrayCannotEncode (count) + |> snd + +/// `This byte array literal contains %d non-ASCII characters.` +let private invalidAsciiWarningMsg count = + FSComp.SR.lexByteArrayOutisdeAscii (count) + |> snd + +[] +let ``Decimal char > 255 is not valid``() = + Fs """ +// Ω +let _ = "\837"B + """ + |> typecheck + |> shouldFail + |> withSingleDiagnostic (Warning 1252, Line 3, Col 10, Line 3, Col 14, invalidCharWarningMsg "\\837" "\\069") + +[] +let ``Decimal char between 128 and 256 is not valid``() = + Fs """ +// ú +let _ = "\250"B + """ + |> typecheck + |> shouldFail + |> withSingleDiagnostic (Warning 1253, Line 3, Col 9, Line 3, Col 16, invalidAsciiWarningMsg 1) + +[] +let ``Decimal char < 128 is valid``() = + Fs """ +let _ = "a\097"B + """ + |> typecheck + |> shouldSucceed + +[] +let ``In verbatim string: \937 is valid and not parsed as single char``() = + Fs """ +if @"\937"B <> "\\937"B then failwith "should not be trigraph" + """ + |> compileExeAndRun + |> shouldSucceed + + +[] +let ``Values in different notations are invalid above 127``() = + Fs """ +[ + "ú"B + "\128"B + "\x80"B + "\u0080"B + "\U00000080"B +] +|> ignore + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 1253, Line 3, Col 5, Line 3, Col 9, invalidAsciiWarningMsg 1) + (Warning 1253, Line 4, Col 5, Line 4, Col 12, invalidAsciiWarningMsg 1) + (Warning 1253, Line 5, Col 5, Line 5, Col 12, invalidAsciiWarningMsg 1) + (Warning 1253, Line 6, Col 5, Line 6, Col 14, invalidAsciiWarningMsg 1) + (Warning 1253, Line 7, Col 5, Line 7, Col 18, invalidAsciiWarningMsg 1) + ] + +[] +let ``Error messages for different notations only span invalid notation``() = + Fs """ +"ok:\061;err:\837;err:\U12345678;err:\U00005678;fin"B +|> printfn "%A" + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 1245, Line 2, Col 23, Line 2, Col 33, "\\U12345678 is not a valid Unicode character escape sequence") + + + // Note: Error for `\U00005678` spans full byte string: + // Is a valid char, but two bytes -> not valid inside byte string + // But check for correct byte happens after string is finished + // (because `B` suffix -> only know at end if it's a byte string) + // -> Don't have direct access to range of invalid char any more + (Error 1140, Line 2, Col 1, Line 2, Col 54,invalidTwoByteErrorMsg 1) + + (Warning 1252, Line 2, Col 14, Line 2, Col 18, invalidCharWarningMsg "\\837" "\\069") + ] + +[] +let ``Decimal char > 255 and > 128 after wrapping triggers two diagnostics``() = + // Currently `\937` trigger TWO diags: + // * Invalid trigraph which gets wrapped -> warning spanning just trigraph + // * Wrapped char is still >= 128 (but < 256) -> warning spanning full byte string + // Those two are checked at different locations (trigraph: while parsing trigraph; 2-byte char: after Byte string was parsed) + // with different infos available (trigraph: trigraph, but don't know if string or byte string; 2-byte-char: byte string, but don't know source notation) + // -> both diags get emitted! + // + // Should be resolved once invalid trigraph gets promoted to error. + Fs """ +// Ω +let _ = "\937"B + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Warning 1252, Line 3, Col 10, Line 3, Col 14, invalidCharWarningMsg "\\937" "\\169") + (Warning 1253, Line 3, Col 9, Line 3, Col 16, invalidAsciiWarningMsg 1) + ] + +[] +let ``Emit both Error and Warning with correct count``() = + Fs """ +let _ = "Ω --- Ω\169 --- Ωä --- Ωü --- Ω"B + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 1140, Line 2, Col 9, Line 2, Col 44,invalidTwoByteErrorMsg 5) + (Warning 1253, Line 2, Col 9, Line 2, Col 44, invalidAsciiWarningMsg 3) + ] diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/CharByteLiterals.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/CharByteLiterals.fs new file mode 100644 index 00000000000..87f895709c7 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/CharByteLiterals.fs @@ -0,0 +1,119 @@ +module Conformance.LexicalAnalysis.CharByteLiterals + +open Xunit +open FSharp.Test.Compiler + +/// `This is not a valid ASCII byte literal. Value should be < 128y.` with note that error soon +let private invalidTrigraphCharWarningMsg = + FSComp.SR.lexInvalidTrigraphAsciiByteLiteral () + |> snd + +[] +let ``all byte char notations pass type check`` () = + Fs """ +[ + 'a'B + '\097'B + '\x61'B + '\u0061'B + '\U00000061'B +] +|> ignore + """ + |> typecheck + |> shouldSucceed + +[] +let ``all byte char notations produce correct value``() = + Fs """ +let chars = [ + 'a'B + '\097'B + '\x61'B + '\u0061'B + '\U00000061'B +] +let expected = 97uy +chars +|> List.iteri (fun i actual -> if actual <> expected then failwithf "[%i]: Expected %A, but was %A" i expected actual) + """ + |> compileExeAndRun + |> shouldSucceed + +[] +let ``byte value > 128uy fails in all char notations``() = + Fs """ +[ + 'ú'B + '\250'B + '\xFA'B + '\u00FA'B + '\U000000FA'B +] +|> ignore + """ + |> typecheck + |> withDiagnostics [ + (Error 1157, Line 3, Col 5, Line 3, Col 9, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + (Error 1157, Line 5, Col 5, Line 5, Col 12, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + (Error 1157, Line 6, Col 5, Line 6, Col 14, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + (Error 1157, Line 7, Col 5, Line 7, Col 18, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + + (Warning 1157, Line 4, Col 5, Line 4, Col 12, invalidTrigraphCharWarningMsg) + ] + +[] +let ``127uy typechecks in char notations``() = + Fs """ +[ + // DELETE -> no direct char representation + '\127'B + '\x7F'B + '\u007F'B + '\U0000007F'B +] +|> ignore + """ + |> typecheck + |> shouldSucceed +[] +let ``128uy fails typecheck in char notations``() = + Fs """ +[ + // Padding Character -> no direct char representation + '\128'B + '\x80'B + '\u0080'B + '\U00000080'B +] +|> ignore + """ + |> typecheck + |> withDiagnostics [ + (Error 1157, Line 5, Col 5, Line 5, Col 12, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + (Error 1157, Line 6, Col 5, Line 6, Col 14, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + (Error 1157, Line 7, Col 5, Line 7, Col 18, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + + (Warning 1157, Line 4, Col 5, Line 4, Col 12, invalidTrigraphCharWarningMsg) + ] + +[] +let ``value out of byte range fails in char notations``() = + Fs """ +[ + 'β'B + '\946'B + // requires more than 2 digits -> no decimal representation + '\u03B2'B + '\U000003B2'B +] +|> ignore + """ + |> typecheck + |> withDiagnostics [ + (Error 1157, Line 3, Col 5, Line 3, Col 9, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + (Error 1157, Line 4, Col 5, Line 4, Col 12, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + + (Error 1157, Line 6, Col 5, Line 6, Col 14, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + (Error 1157, Line 7, Col 5, Line 7, Col 18, "This is not a valid byte character literal. The value must be less than or equal to '\\127'B.") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/Strings.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/Strings.fs new file mode 100644 index 00000000000..28922805ca3 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/LexicalAnalysis/Strings.fs @@ -0,0 +1,63 @@ +module Conformance.LexicalAnalysis.Strings + +open Xunit +open FSharp.Test.Compiler + +/// `'%s' is not a valid character literal.` with note about wrapped value and error soon +let private invalidCharWarningMsg value wrapped = + FSComp.SR.lexInvalidCharLiteralInString (value, wrapped) + |> snd + +[] +let ``Decimal char > 255 is not valid``() = + Fs """ +printfn "Ω\937" + """ + |> typecheck + |> shouldFail + |> withSingleDiagnostic (Warning 1252, Line 2, Col 11, Line 2, Col 15, invalidCharWarningMsg "\\937" "\\169") + +[] +let ``Decimal char between 128 and 256 is valid``() = + Fs """ +printfn "ú\250" + """ + |> typecheck + |> shouldSucceed + +[] +let ``Decimal char < 128 is valid``() = + Fs """ +printfn "a\097" + """ + |> typecheck + |> shouldSucceed + +[] +let ``In verbatim string: \937 is valid and not parsed as single char``() = + Fs """ +if @"\937" <> "\\937" then failwith "should not be trigraph" + """ + |> compileExeAndRun + |> shouldSucceed + +[] +let ``Error message for invalid decimal char contains only invalid trigraph``() = + Fs """ +printfn "foo\937bar" + """ + |> typecheck + |> shouldFail + |> withSingleDiagnostic (Warning 1252, Line 2, Col 13, Line 2, Col 17, invalidCharWarningMsg "\\937" "\\169") + +[] +let ``Error messages for different notations only span invalid notation``() = + Fs """ +printfn "ok:\061;err:\937;err:\U12345678;ok:\U00005678;fin" + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 1245, Line 2, Col 31, Line 2, Col 41, "\\U12345678 is not a valid Unicode character escape sequence") + (Warning 1252, Line 2, Col 22, Line 2, Col 26, invalidCharWarningMsg "\\937" "\\169") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 9d65f2bef9b..b6014377886 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -92,6 +92,9 @@ + + + diff --git a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_BogusLongUnicodeEscape.fs b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_BogusLongUnicodeEscape.fs index 60476dd8679..e2e49154ba6 100644 --- a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_BogusLongUnicodeEscape.fs +++ b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_BogusLongUnicodeEscape.fs @@ -10,5 +10,5 @@ let bogusString02 = "\UFFFF0000" exit 1 //This Unicode encoding is only valid in string literals -//\\U00110000 is not a valid Unicode character escape sequence -//\\UFFFF0000 is not a valid Unicode character escape sequence +//\\U00110000 is not a valid Unicode character escape sequence +//\\UFFFF0000 is not a valid Unicode character escape sequence diff --git a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteCharUnicodeChar01.fs b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteCharUnicodeChar01.fs index 1eae16e8719..b07fdbb2586 100644 --- a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteCharUnicodeChar01.fs +++ b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteCharUnicodeChar01.fs @@ -4,7 +4,7 @@ // Verify error when trying to take the byte value of // a unicode character literal. -//This is not a valid byte literal +//This is not a valid byte character literal. The value must be less than or equal to '\\127'B. let _ = '\u2660'B diff --git a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteChars02.fs b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteChars02.fs index 0f5b773a644..e197d358871 100644 --- a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteChars02.fs +++ b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteChars02.fs @@ -2,7 +2,7 @@ // Verify getting the byte value of a char works past the first 128 ASCII characters // It is not valid because it must be <= 127 -//This is not a valid byte literal +//This is not a valid byte character literal. The value must be less than or equal to '\\127'B. if 'ú'B <> 250uy then exit 1 diff --git a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteStrUnicodeChar01.fs b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteStrUnicodeChar01.fs index a921681d40a..5ef49323688 100644 --- a/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteStrUnicodeChar01.fs +++ b/tests/fsharpqa/Source/Conformance/LexicalAnalysis/StringsAndCharacters/E_ByteStrUnicodeChar01.fs @@ -4,7 +4,7 @@ // Verify error when trying to take the byte string of // a string literal with unicode characters -//This byte array literal contains characters that do not encode as a single byte +//This byte array literal contains 1 characters that do not encode as a single byte let _ = "\u2660"B