Skip to content

binding: reject the implicit conversion from byte to char - #18

Merged
rameel merged 1 commit into
mainfrom
binding/byte-to-char-conversion
Nov 17, 2026
Merged

rameel merged 1 commit into
mainfrom
binding/byte-to-char-conversion

Conversation

@rameel

@rameel rameel commented Nov 17, 2026

Copy link
Copy Markdown
Owner

The table of implicit primitive conversions in TypeUtils.CanConvertPrimitive followed the widening rules of the reflection binder, which convert byte to char. C# has no such implicit conversion, but a byte argument was accepted for a char parameter and even preferred the char overload to the int overload. For example, "abc".IndexOf(97 :> byte) called IndexOf(char) and returned 0, and a conditional expression with byte and char branches had the type char.

This PR removes the conversion, so a byte argument selects the overload that C# would select, and a call fails when only a char parameter could accept the argument. In that case the error still reads Ambiguous match found, which is a separate issue.

The table of implicit primitive conversions followed the widening rules
of the reflection binder, which convert byte to char. C# has no such
implicit conversion, but a byte argument was accepted for a char
parameter and even preferred the char overload to the int overload.
For example, '"abc".IndexOf(97 :> byte)' called IndexOf(char), and a
conditional expression with byte and char branches had the type char.

Remove the conversion, so a byte argument selects the overload that C#
would select, or fails when only a char parameter could accept it.
@rameel
rameel merged commit f336817 into main Nov 17, 2026
1 check passed
@rameel
rameel deleted the binding/byte-to-char-conversion branch November 17, 2026 17:58
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