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

Improve errors for use-before-init within init() routines #26919

Open
bradcray opened this issue Mar 13, 2025 · 0 comments
Open

Improve errors for use-before-init within init() routines #26919

bradcray opened this issue Mar 13, 2025 · 0 comments

Comments

@bradcray
Copy link
Member

In a recent SO question, a user expressed confusion over getting a "use before init" error for a case like this:

record R {
  var x: [1..3] int;
  proc init() {
    for i in 1..3 do x[i] = i;  // error: field "x" used before it is initialized
  }
}

var myR: R;

which is understandable since it appears as though the line in question is initializing the array rather than using it, logically speaking. Using --detailed-errors didn't seem to improve the message as of Chapel 2.4.

Here, I'm wondering whether we could specialize this error message for the initializer context to add some additional detail like "Within an initializer, each field must be initialized using an assignment of the form [this.]field = expr; before it is referenced." We could potentially add "Or use an init this; statement before referencing the field to opt into default field initialization."

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

No branches or pull requests

1 participant