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

Warn for generic declared return types without (?) #23356

Merged
merged 14 commits into from
Sep 13, 2023

Conversation

mppf
Copy link
Member

@mppf mppf commented Sep 13, 2023

For https://github.com/Cray/chapel-private/issues/5229 / https://github.com/Cray/chapel-private/issues/4736#issuecomment-1666320252

Continuing #22745 and #23291, this PR adds a warning for routines declared with a generic return type that does not include (?). Note that we already have a number of problems using domain or domain(?) as a return or variable type (#23355, #23357, #23358); as a result domain(?) cannot currently be used as a declared return type.

While there, this PR adds checking to fix #23346 by making (?) on a concrete formal type into a compilation error. It also adds testing for the variable and return type cases to make sure that they also result in a compilation error.

For example:

record R { type t; }

proc a() : R { // warning
  return new R(int);
}
a();

proc b() : R(?) { // OK
  return new R(int);
}
b();

proc returnGenericType() type { return R; }

proc c() : returnGenericType() { // warning
  return new R(int);
}
c();

proc d() : returnGenericType()(?) { // OK
  return new R(int);
}
d();

Reviewed by @vasslitvinov and @lydia-duncan - thanks!

  • full comm=none testing
  • full gasnet testing

@mppf mppf changed the title Warn generic return type no q Warn for generic declared return types without (?) Sep 13, 2023
@mppf mppf force-pushed the warn-generic-return-type-no-q branch from a1b3598 to d889ebc Compare September 13, 2023 18:55
---
Signed-off-by: Michael Ferguson <[email protected]>
---
Signed-off-by: Michael Ferguson <[email protected]>
---
Signed-off-by: Michael Ferguson <[email protected]>
For arrays/ferguson/tuples/t3

---
Signed-off-by: Michael Ferguson <[email protected]>
For constrained-generics/ucol/cwailes-1/confused-arg-error

---
Signed-off-by: Michael Ferguson <[email protected]>
---
Signed-off-by: Michael Ferguson <[email protected]>
---
Signed-off-by: Michael Ferguson <[email protected]>
For functions/lydia/declaredGenericReturnType.chpl
    functions/vass/declaredGenericReturnTuple.chpl

---
Signed-off-by: Michael Ferguson <[email protected]>
@mppf mppf force-pushed the warn-generic-return-type-no-q branch from a2959cd to 006ecca Compare September 13, 2023 20:01
---
Signed-off-by: Michael Ferguson <[email protected]>
Copy link
Member

@lydia-duncan lydia-duncan left a comment

Choose a reason for hiding this comment

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

Test changes all look reasonable to me, too!

@mppf mppf merged commit 6eb2f16 into chapel-lang:main Sep 13, 2023
7 checks passed
@mppf mppf deleted the warn-generic-return-type-no-q branch September 13, 2023 20:53
mppf added a commit that referenced this pull request Sep 21, 2023
This PR updates the language specification to cover the changes in PRs
#23291 #22784 #22745 #23356 where marking a generic type with `(?)` is
now needed.

This PR adds several new spec sections:
 * Fields with Generic Types
 * Fully Defaulted Generic Types
 * Marking Generic Types

Reviewed by @lydia-duncan - thanks!
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.

Compiler doesn't correctly report error for applying (?) to non-generic types
3 participants