Skip to content

Compiler desugars char-array literals to StringBuilder::new (blocks deprecating ::new) #3572

@bobzhang

Description

@bobzhang

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::newStringBuilder::StringBuilder and tagging the old name #alias(new, deprecated)):

  • builtin/char.mbt:443fn 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:136self.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions