Skip to content

bug - comprehension over a Rust interop iterator emits .iter() and fails to compile #1490

Description

@dannymeijer

Area

Compiler (frontend/backend/codegen)

Summary

A list comprehension over a Rust-interop iterator typechecks, but emits .iter() on a value that consumes itself, so the generated Rust does not compile.

std::env::Args is an Iterator by value. It has no iter() method. The comprehension lowers as though the source were a collection.

Reproduction steps

from rust::std::env import args


pub def main() -> None:
    arguments: list[str] = [argument for argument in args()]
    println(f"{len(arguments)}")
incan check src/main.incn     # passes
incan oven bake --project .   # generated Rust fails to compile

A plain for loop over the same value lowers correctly, which is the workaround:

    mut arguments: list[str] = []
    for argument in args():
        arguments.append(argument)

Output / logs

error[E0599]: no method named `iter` found for struct `Args` in the current scope
   --> src/main.rs:91:10
    |
 90 |       let arguments: Vec<String> = (args())
    |  __________________________________-
 91 | |         .iter()
    | |_________-^^^^
    |
    = help: items from traits can only be used if the trait is implemented and in scope
note: `Iterable` defines an item `iter`, perhaps you need to implement it

Environment

  • Compiler built from 0.6.0-dev.4 at 0a8395835
  • Stage: emission (comprehension lowering over a rust:: interop iterator)
  • Impact: blocks incan oven bake for any component whose entrypoint reads process arguments this way, and therefore blocks incan test for that component. The for-loop form above is a semantically identical workaround and is what the affected source now does, marked with a TODO.
  • Note the asymmetry: for x in args() lowers correctly while [x for x in args()] does not, so the two forms disagree on what an interop iterator is.
  • Found in the Incan-authored Oven control plane under workspaces/oven while making its test suite runnable (feature - RFC 119 native Rust facets and direct-rustc planning #1037, PR chore - retain the Incan-authored Oven control plane (#1037) #1487).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingincan compilerSuggestions, features, or bugs related to the Compiler (frontend/backend/codegen)

    Type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions