Skip to content

parser: promote char operands of unary and shift operators to int - #24

Merged
rameel merged 1 commit into
mainfrom
parser/char-numeric-promotion
Nov 18, 2026
Merged

rameel merged 1 commit into
mainfrom
parser/char-numeric-promotion

Conversation

@rameel

@rameel rameel commented Nov 18, 2026

Copy link
Copy Markdown
Owner

The unary -, +, and ~ operators and the shift operators rejected a char operand, although C# converts it to int, as it does for sbyte, byte, short, and ushort. For example, -'a' failed with Unary operator '-' cannot be applied to operand of type 'System.Char', and 'a' << 1 failed with Operator '<<' cannot be applied to operands of type 'System.Char' and 'System.Int32'. Binary arithmetic and comparisons with char already worked.

This PR applies unary numeric promotion to these operands in one place and includes char in it. The shift operators still reject a count that does not convert to int, such as 1 << 1u, and a value that is not an integer, such as 1.5 >> 1.

The unary '-', '+', and '~' operators and the shift operators rejected
a char operand, although C# converts it to int, as it does for sbyte,
byte, short, and ushort. For example, -'a', ~'a', 'a' << 1, and
1 << 'a' failed with "cannot be applied to operand(s) of type
'System.Char'".

Apply unary numeric promotion to these operands in one place and
include char in it. The shift operators still reject a count that does
not convert to int, such as '1 << 1u', and a value that is not an
integer, such as '1.5 >> 1'.
@rameel
rameel merged commit e591991 into main Nov 18, 2026
1 check passed
@rameel
rameel deleted the parser/char-numeric-promotion branch November 18, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant