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

add split-init error when uninitialized var used as actual #26497

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

arezaii
Copy link
Contributor

@arezaii arezaii commented Jan 8, 2025

This adds detection of an uninitialized variable used as an actual to a non-out formal. The previous error was a generic failure to resolve function [NoMatchingCandidates] and this improves the message by indicating that the candidate did not match because of the uninitialized actual passed to a non-out formal.

resolves https://github.com/Cray/chapel-private/issues/6624

Example program:

proc fn(const arg) {
  arg;
}
proc main() {
  var x;
  fn(x);
  x=5;
}

in production this produces the following error message:

MyTestModule.chpl:9: In function 'main':
MyTestModule.chpl:10: error: 'x' is not initialized and has no type
MyTestModule.chpl:10: note: cannot find initialization point to split-init this variable
MyTestModule.chpl:11: note: 'x' is used here before it is initialized

previous error message compiling with chpl MyTestModule.chpl --dyno --detailed-errors:

─── error in MyTestModule.chpl:11 [NoMatchingCandidates] ───
  Unable to resolve call to 'fn': no matching candidates.
       |
    11 |   fn(x);
       |
  
  The following candidate didn't match because an actual couldn't be passed to a formal:
      |
    6 | proc fn(const arg) {
      |         ⎺⎺⎺⎺⎺⎺⎺⎺⎺
    7 |   arg;
    8 | }
      |
  The formal 'arg' expects a value of type '?', but the actual was a value of type 'UnknownType'.
       |
    11 |   fn(x);
       |      ⎺
       |

Updated error message with -dyno --detailed-errors:

─── error in MyTestModule.chpl:11 [NoMatchingCandidates] ───
  Unable to resolve call to 'fn': no matching candidates.
       |
    11 |   fn(x);
       |
  
  The following candidate didn't match because an actual couldn't be passed to a formal:
      |
    6 | proc fn(const arg) {
      |         ⎺⎺⎺⎺⎺⎺⎺⎺⎺
    7 |   arg;
    8 | }
      |
  The actual 'x' expects to be split-initialized because it is declared without a type or initialization expression here:
       |
    10 |   var x;
       |       ⎺
       |
  The call to fn occurs before any valid initialization points:
       |
    11 |   fn(x);
       |      ⎺
       |
  The call to 'fn' cannot initialize 'x' because only 'out' formals can be used to split-initialize. However, 'x' is passed to formal 'arg' which has intent 'const'.

updated error message with --dyno --no-detailed-errors

MyTestModule.chpl:9: In function 'main':
MyTestModule.chpl:11: error: unable to resolve call to 'fn': no matching candidates
MyTestModule.chpl:1: In module 'MyTestModule':
MyTestModule.chpl:6: note: the following candidate didn't match because an actual couldn't be passed to a formal
MyTestModule.chpl:9: In function 'main':
MyTestModule.chpl:11: note: The actual 'x' expects to be split-initialized because it is declared without a type or initialization expression here

TESTING:

  • paratest [Summary: #Successes = 17676 | #Failures = 0 | #Futures = 891]
  • gasnet paratest [Summary: #Successes = 17857 | #Failures = 0 | #Futures = 900]

frontend/lib/resolution/Resolver.cpp Outdated Show resolved Hide resolved
frontend/lib/resolution/Resolver.cpp Outdated Show resolved Hide resolved
frontend/lib/resolution/Resolver.cpp Outdated Show resolved Hide resolved
frontend/lib/resolution/Resolver.cpp Outdated Show resolved Hide resolved
frontend/lib/resolution/resolution-error-classes-list.cpp Outdated Show resolved Hide resolved
frontend/lib/resolution/Resolver.cpp Outdated Show resolved Hide resolved
Signed-off-by: Ahmad Rezaii <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants