Skip to content

Better issue when .str used instead of .data #12

Description

@ArtemkaKun
fn to_upper(s string) -> string {
    unsafe {
        mut b := mem.alloc(s.len + 1)
        for i in 0 .. s.len {
            if s.str[i] >= `a` && s.str[i] <= `z` {
                b[i] = s.str[i] - 32
            } else {
                b[i] = s.str[i]
            }
        }
        b[s.len] = 0
        return tos(b)
    }
}
C compiler output:
/home/yuart/Projects/spawn/out.c: In function ‘main___to_upper’:
/home/yuart/Projects/spawn/out.c:1349:43: error: subscripted value is neither array nor pointer nor vector
 1349 |                         if (!((string__str[i] < 'a')) && (string__str[i] < 'z' || string__str[i] == 'z')) {
      |                                           ^
/home/yuart/Projects/spawn/out.c:1349:70: error: subscripted value is neither array nor pointer nor vector
 1349 |                         if (!((string__str[i] < 'a')) && (string__str[i] < 'z' || string__str[i] == 'z')) {
      |                                                                      ^
/home/yuart/Projects/spawn/out.c:1349:94: error: subscripted value is neither array nor pointer nor vector
 1349 |                         if (!((string__str[i] < 'a')) && (string__str[i] < 'z' || string__str[i] == 'z')) {
      |                                                                                              ^
/home/yuart/Projects/spawn/out.c:1350:51: error: subscripted value is neither array nor pointer nor vector
 1350 |                                 b[i] = string__str[i] - 32;
      |                                                   ^
/home/yuart/Projects/spawn/out.c:1352:51: error: subscripted value is neither array nor pointer nor vector
 1352 |                                 b[i] = string__str[i];
      |                                                   ^

error: C compiler failed

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