Skip to content

Confusing error message on missing self, potentially indicating bigger issues with type parameters #7645

Description

@ironcev

E.g., compiling this code:

library;

struct S { }

impl S {
    fn use_self() {
        let _ = self.x();
    }

    fn x(self) -> u64 {
        0
    }
}

emits:

5 | impl S {
6 |     fn use_self() {
7 |         let _ = self.x();
  |                 ^^^^ Identifier "self" was used as a variable, but it is actually a generic type parameter.

The error message is confusing, but aside from that, it looks like we might have a bigger issue here with injecting type parameters, because self is not a type parameter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilerGeneral compiler. Should eventually become more specific as the issue is triagedcompiler: frontendEverything to do with type checking, control flow analysis, and everything between parsing and IRgen

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions