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

Implemented a warning to prevent varaibles and constructors from having the same name #2580

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tobiaj10
Copy link
Contributor

No description provided.

@tobiaj10 tobiaj10 marked this pull request as ready for review August 12, 2022 16:37
@@ -12800,6 +12800,10 @@ private class ClonerKeepLocalVariablesIfTypeNotSet : Cloner {
// Check if the head of the pattern is a constructor or a variable
if (ctors.TryGetValue(idpat.Id, out ctor)) {
/* =[3]= */
if (ctor != null && idpat.Arguments == null && ctor.Formals.Count != 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition of this if and the next one are quite similar. Consider combining the two:

if (ctor != null && idpat.Arguments == null) {
  if (ctor.Formals.Count == 0) {
    // nullary constructor without () -- so convert it to a constructor
    idpat.MakeAConstructor();
  } 
  else {
    this.reporter.Warning(MessageSource.Resolver, pat.Tok,
    $"Variable name '{pat}' has the same name as a datatype constructor that's in scope at this location");
  }
}

@keyboardDrummer
Copy link
Member

Looks great! I left one refactoring comment.

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