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

check use before defined in init exprs #26157

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

arezaii
Copy link
Collaborator

@arezaii arezaii commented Oct 29, 2024

This updates how dyno detects use-before-definition errors. It should resolve https://github.com/Cray/chapel-private/issues/6666.

Fixing the missing error in Dyno updated the production error messages for use-before-define errors. Tests have been updated to reflect the changes.

A special case of use-before-defined for self-definition, has been added.
For example, given:

var f4 = f4 * 4;

the previous production error would be:

MyTestModule.chpl:1: In module 'MyTestModule':
MyTestModule.chpl:1: error: 'f4' used before defined
MyTestModule.chpl:1: note: defined here

The new production error will be:

MyTestModule.chpl:1: In module 'MyTestModule':
MyTestModule.chpl:1: error: statement references variable 'f4' before it is defined

and more detail can be viewed by compiling with --detailed-errors:

─── error in MyTestModule.chpl:1 [SelfDefinition] ───
  Statement references variable 'f4' before it is defined.
  In the following statement:
      |
    1 | var f4 = f4 * 4;
      |
  the variable 'f4' is used to define itself here:
      |
    1 | var f4 = f4 * 4;
      |          ⎺⎺
      |
  Variables cannot be used to define themselves.

Future work remains to specialize error messages for related cases when shadowing occurs. For example, the following codes exhibit self-definition and use-before-defined errors, respectively:

var x = 42;
{
  var x = 2 * x;
}
var y = 42;
{
  var x = 2*y;
  var y = 2*x;
}

It would be nice to indicate to users that the outer variables in each case are supplanted by the local definition of a variable by the same name.

TESTING:

  • paratest [Summary: #Successes = 17740 | #Failures = 0 | #Futures = 898]
  • gasnet paratest [Summary: #Successes = 17924 | #Failures = 0 | #Futures = 909]

mppf

This comment was marked as outdated.

@arezaii arezaii marked this pull request as ready for review November 12, 2024 20:49
@arezaii arezaii force-pushed the dyno-use-before-defined branch from 5f298c3 to 597b76f Compare November 14, 2024 20:46
@arezaii arezaii force-pushed the dyno-use-before-defined branch from 8bfc21d to 1860214 Compare November 27, 2024 00:20
@arezaii arezaii force-pushed the dyno-use-before-defined branch from ba2320e to 15dcba5 Compare January 8, 2025 23:38
Signed-off-by: Ahmad Rezaii <[email protected]>
@arezaii arezaii force-pushed the dyno-use-before-defined branch 2 times, most recently from b639c56 to a88d486 Compare January 14, 2025 20:12
@arezaii arezaii force-pushed the dyno-use-before-defined branch 4 times, most recently from ae1709d to d210a64 Compare January 17, 2025 01:25
@arezaii arezaii force-pushed the dyno-use-before-defined branch from d210a64 to aa050af Compare January 17, 2025 01:31
@arezaii arezaii force-pushed the dyno-use-before-defined branch from 577833c to 816c5c3 Compare January 23, 2025 18:05
@arezaii arezaii force-pushed the dyno-use-before-defined branch from 816c5c3 to abeaa8a Compare January 23, 2025 18:19
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.

3 participants