The MoonBit compiler desugars array literals like [char_a, char_b] into a StringBuilder::new + to_string() call when the expected type is String. Affected sites in core today (visible after renaming StringBuilder::new → StringBuilder::StringBuilder and tagging the old name #alias(new, deprecated)):
builtin/char.mbt:443 — fn char_to_string(char) -> String { [char] }
builtin/show.mbt:83 — [to_hex_digit(b / 16), to_hex_digit(b % 16)] in Byte::to_hex
builtin/traits.mbt:136 — self.write_string([value]) in impl Logger with write_char
Each of these emits Warning (deprecated): \new` is deprecated, use `StringBuilder` insteadeven though the source code never namesStringBuilder::new. With --deny-warn(used bybleeding-check, pre-release-check, stable-check`) the build fails.
Because the compiler hard-codes the symbol name, the same warning would be emitted in every downstream user file that uses a char-array string literal — not just core.
Workarounds
PR #(this PR) lands the rename as a non-deprecated alias (#alias(new) instead of #alias(new, deprecated)) so both names are valid and neither warns. Fully deprecating StringBuilder::new is blocked on the compiler emitting StringBuilder::StringBuilder (or just StringBuilder) in the desugar instead.
Ask
Update the compiler to desugar char-array string literals to the new constructor name. Once that ships, this issue can be closed by changing the alias attribute back to #alias(new, deprecated) here in core.
The MoonBit compiler desugars array literals like
[char_a, char_b]into aStringBuilder::new+to_string()call when the expected type isString. Affected sites in core today (visible after renamingStringBuilder::new→StringBuilder::StringBuilderand tagging the old name#alias(new, deprecated)):builtin/char.mbt:443—fn char_to_string(char) -> String { [char] }builtin/show.mbt:83—[to_hex_digit(b / 16), to_hex_digit(b % 16)]inByte::to_hexbuiltin/traits.mbt:136—self.write_string([value])inimpl Logger with write_charEach of these emits
Warning (deprecated): \new` is deprecated, use `StringBuilder` insteadeven though the source code never namesStringBuilder::new. With--deny-warn(used bybleeding-check,pre-release-check,stable-check`) the build fails.Because the compiler hard-codes the symbol name, the same warning would be emitted in every downstream user file that uses a char-array string literal — not just core.
Workarounds
PR #(this PR) lands the rename as a non-deprecated alias (
#alias(new)instead of#alias(new, deprecated)) so both names are valid and neither warns. Fully deprecatingStringBuilder::newis blocked on the compiler emittingStringBuilder::StringBuilder(or justStringBuilder) in the desugar instead.Ask
Update the compiler to desugar char-array string literals to the new constructor name. Once that ships, this issue can be closed by changing the alias attribute back to
#alias(new, deprecated)here in core.