Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

cast mutable array to immutable array #579

Closed
@Yu-zh

Description

@Yu-zh

Hi,

The following code attempts to cast a mutable array to an immutable array, but traps at runtime:

(module
  (type $ma (array (mut i32)))
  (type $ima (array i32))
  (func (param $a (ref $ma)) (result (ref $ima))
    (local.get $a)
    (ref.cast (ref $ima))
  )
)

Use Case: I'm implementing strings as immutable arrays in my language. For operations like string append, I need to:

  1. Allocate a mutable array
  2. Write the characters
  3. Convert it to an immutable array

Questions:

  1. Is there a way to cast from mutable to immutable arrays?
  2. If not, what's the recommended approach for implementing immutable string operations?

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions