Skip to content

c = s[i] on a string warns 'unresolved type in codegen, defaulting to int' #3479

Closed

Description

@nicolas-maman

Binding one byte of a string to a local warns, and the local is typed by a default:

main() {
    s = "A"
    c = s[0]
    println(c)
}
warning: unresolved type in codegen, defaulting to int
  --> b.ae:3:5
3 |     c = s[0]

It then prints 65. A string parameter does the same (c = text[i]).

Expected: no warning. s[i] reads one byte (language reference, strings), so c gets the type that read has, as c = xs[0] does for an array. The default happens to give the right value here, but a typecheck that leaves a local's type to codegen is the failure, and the warning fails make check-examples, which builds every example with warnings as errors.

Found writing the Rosetta Code tranche of #1191 (PR #3477): Caesar cipher (c = text[i] and then match c { 65..=90 -> ... }) waits for it. Filed for the next batch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions