Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple constructors silently ignored #2825

Closed
gwillen opened this issue Jul 6, 2012 · 2 comments
Closed

Multiple constructors silently ignored #2825

gwillen opened this issue Jul 6, 2012 · 2 comments
Milestone

Comments

@gwillen
Copy link
Contributor

gwillen commented Jul 6, 2012

class example {
  let x: int;
  new() {
    self.x = 1;
  }
  new(x_: int) {
    self.x = x_;
  }
}

fn main(_args: [str]) {
  let e: example = example();
}



Glenn-Willens-MacBook-Pro:rust gwillen$ rustc classes.rs 
classes.rs:29:19: 29:29 error: this function takes 1 parameter but 0 parameters were supplied
classes.rs:29   let x: example = example();
                                 ^~~~~~~~~~

The compiler will let you give a class multiple constructors, and compiles it without error, but throws away all except the last one.

@ghost ghost assigned catamorphism Jul 6, 2012
@gwillen
Copy link
Contributor Author

gwillen commented Jul 7, 2012

Oh, destructors too, as it turns out. Same problem.

@gwillen
Copy link
Contributor Author

gwillen commented Jul 7, 2012

Oh, and methods. And with fields it's not silent, but I can make it produce some bizarre errors, including an LLVM assert. Assuming this is all probably related.

saethlin pushed a commit to saethlin/rust that referenced this issue Apr 11, 2023
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Update Rust toolchain from nightly-2023-10-16 to nightly-2023-10-17
without any other source changes.
This is an automatically generated pull request. If any of the CI checks
fail, manual intervention is required. In such a case, review the
changes at https://github.com/rust-lang/rust from
rust-lang@42b1224
up to
rust-lang@49691b1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants