Skip to content

Char-Byte outside of ASCII range can be represented in decimal char notation #15868

@Booksbaum

Description

@Booksbaum

Byte in char form is limited to ASCII range:

> 'a';;
val it: char = 'a'
> int 'a';;
val it: int = 97
> 'a'B;;
val it: byte = 97uy

> 'ú';;
val it: char = 'ú'
> int 'ú';;
val it: int = 250
> 'ú'B;;
  ^^^^
stdin(17,1): error FS1157: This is not a valid byte literal

Same limit for UTF16 notation:

> '\u00FA';;
val it: char = 'ú'
> '\u00FA'B;;
  ^^^^^^^^^
stdin(24,1): error FS1157: This is not a valid byte literal

BUT: in decimal notation the value can span all of byte range:

> '\250';;
val it: char = 'ú'
> '\250'B;;
val it: byte = 250uy

(fable repl; sharplab)

(numbers over 255 aren't valid: '\256'B -> error FS1157: This is not a valid byte literal)

(other char notations for byte aren't currently supported. See #15867)

Expected behavior

decimal notation and other notations should have same range limits.

Actual behavior

While char & UTF16-hex must be <128, decimal can be any byte-value (<256).

It's called ASCII byte in the docs, so the correct range is probably 0..127. (There's also a test check for error when >= 128) And the 255 boundary is then most likely a copy&paste error from 3-digit decimal char

Though I personally would prefer char byte to allow all of byte range (0..255):

  • there's \unicode notation which already signals there's "more" than just ASCII
  • slightly strange to have a valid char with a value inside byte range -- but invalid byte char because >= 128
  • In Byte String array values over 127 are possible:
    > "ú\250\xFA\u00FA\U000000FA"B;;
    val it: byte array = [|250uy; 250uy; 250uy; 250uy; 250uy|]


Whatever is desired: I would give it a try fixing/adjusting it (together with #15867). I just need to know what range should be valid.






Related information

  • Operating system: Windows 11 x64
  • dotnet --version: 7.0.307, 8.0.100-preview.7.23376.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions