Skip to content

ICE when passing self as the value to a nonexistent struct field #5439

Closed
@doy

Description

@doy
struct Foo {
    foo: int,
}

struct Bar {
    bar: int,
}

impl Bar {
    fn make_foo (&self, i: int) -> ~Foo {
        return ~Foo { nonexistent: self, foo: i };
    }
}

fn main () {
    let bar = Bar { bar: 1 };
    let foo = bar.make_foo(2);
    io::println(fmt!("%d", foo.foo));
}

produces

test2.rs:11:22: 11:39 error: structure has no field named `nonexistent`
test2.rs:11         return ~Foo { nonexistent: self, foo: i };
                                  ^~~~~~~~~~~~~~~~~
error: internal compiler error: no type for node 23: expr self (id=23) in fcx 7f5d0c438ce0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions