Skip to content

coroc: support for range loops over strings #138

@chriso

Description

@chriso

The desugaring pass should be updated to desugar for range loops over strings:

var s string
for range string { ... }
for index := range string { ... }
for index, rune := range string { ... }

At first glance it should simply be a matter of adding *types.Basic (with .Kind() == types.String) to the case where we handle *types.Array and *types.Slice here, however range loops are a bit different when strings are involved. When indexing a string you get back a byte. When using a for range loop with a string you get a rune along with an index representing its offset in the string. More info in https://go.dev/blog/strings.

The desugaring pass should use utf.DecodeRuneInString to parse runes from strings iteratively.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions