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

Default argument expressions should inherit throwability from calling context #1400

Open
awesomekling opened this issue Feb 26, 2023 · 4 comments

Comments

@awesomekling
Copy link
Contributor

We currently refuse to compile this:

fn foo(x: [i64] = []) {
}

fn main() throws {
    foo()
}

We should allow it, since any error thrown would be thrown in the main context, which is throwsy :)

@0GreenClover0
Copy link
Contributor

0GreenClover0 commented Feb 26, 2023

Default argument expressions that throw are supported, but the function (foo, in this example) has to be marked as throws

@awesomekling
Copy link
Contributor Author

Ah, good point! But yeah, we're not throwing inside foo, so it's still the calling context that needs to be throwsy IMO :)

@awesomekling awesomekling changed the title Allow default argument expressions that may throw Default argument expressions should inherit throwability from calling context Feb 27, 2023
@ADKaster
Copy link
Member

ADKaster commented Mar 4, 2023

Another thought is that it would be nice if [] didn't throw at all. In the C++ it won't allocate anything on the heap, and is actually infallible. (or if that's not true either, we should make it true in the C++).

@awesomekling
Copy link
Contributor Author

Another thought is that it would be nice if [] didn't throw at all. In the C++ it won't allocate anything on the heap, and is actually infallible. (or if that's not true either, we should make it true in the C++).

Trouble there is that arrays have reference semantics, so after passing an empty array ("by value") to a function that pushes something into it, the caller and the callee would see different array backing stores.

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

3 participants