-
Notifications
You must be signed in to change notification settings - Fork 421
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 variables/fields declared with generic type without ?
#22745
Conversation
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
Necessary for change to DefaultAssociativeDomRehashHelper in upcoming commit. --- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
For test/classes/jade/owned/assign-op.chpl --- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
For test/functions/intents/out/out-generic-type-set-assign.chpl --- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
For test/types/records/generic/warn-field-generic-declared-type.chpl --- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
Makes the code clearer and avoids the new warning. --- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
For test/types/partial/bad-managed-init.chpl --- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
To solve the warning in initeq.chpl, I needed to change it to use `T(?)` but that caused a compilation error due to a workaround added in PR chapel-lang#13315 Removing the workaround entirely caused failures for 3 tests: classes/ferguson/recursive/issue-12612.chpl types/records/recursive/generic-simple.chpl types/records/vass/issue-11846-a.chpl So, the workaround seems necessary in some cases today. This commit adjusts that workaround to be slightly more focused (now it requires that the parentSymbol is a TypeSymbol) so that the 3 tests above can use it but it does not interfere with initeq.chpl. --- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
--- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
d9f0142
to
897cf70
Compare
@@ -1,3 +1,5 @@ | |||
genericChannelInInit2.chpl:7: warning: please use '?' when declaring a field with generic type | |||
genericChannelInInit2.chpl:7: note: for example with 'fileWriter(?)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mppf: Mostly rhetorical question for me, but may be of greater interest to a reviewer: How did you decide whether to keep a test working by updating its source vs. its .good/.bad file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking, if the .good file indicated that the test was for some sort of error message with an erroneous program, then I updated the .good file. If the test seemed to be something that we want to run & continue working, I updated the test itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Please see my comment.
t == dtIteratorRecord || t == dtIteratorClass || | ||
t == dtAnyPOD || | ||
t == dtOwned || t == dtShared || | ||
t == dtAnyRecord; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please double-check whether the above needs dtBorrowed, dtUnmanaged, dtAnyManagementAnyNilable, dtAnyNilable(??).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are covered by isBuiltinGenericClassType
which is called as the first option in the ||
clauses.
This PR takes two steps: 1. It makes it legal to write `class C : GenericParent(?)` in order to clearly indicate that `class C` is generic due to inheriting from a generic class. 2. It adds a warning to request this form when inheriting from a generic class, and a related error for the case of `class C : ConcreteParent(?)`. The rationale for the warning is that, if code compiling without these warnings (including the field warning from PRs #22745 and #22697) then it is syntactically apparent whether or not a class or record is generic. That means that, in the future, if we make these errors, a) the compiler doesn't have to work as hard to know if a type is generic and b) neither do users. Reviewed by @vasslitvinov - thanks! - [x] full comm=none testing
Adjusts the warnings from PRs chapel-lang#22697 chapel-lang#22745 and chapel-lang#22784 to include a note about the warning possibly being an error in the future when compiling with `--warn-unstable`. --- Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
Adjusts the warnings from PRs #22697 #22745 and #22784 to include a note about the warning possibly being an error in the future when compiling with `--warn-unstable`. Reviewed by @lydia-duncan - thanks! - [x] full comm=none testing
For Cray/chapel-private#5229 / Cray/chapel-private#4736 (comment) 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: ``` chapel 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! - [x] full comm=none testing - [x] full gasnet testing
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!
Resolves https://github.com/Cray/chapel-private/issues/5032
This PR adds a warning for these cases:
var x: someGenericType
for fields and variables (needsomeGenericType(?)
)proc foo(type t) { var x: t; }
-- similarly tovar x: someGenericType
var x: f();
wheref()
returns a generic type, for fields and variablesIn the above,
someGenericType
includesdomain
or user records/classes that are generic. Note that PR #22697 added a warning for fields declared with typedomain
or fields of class type with generic management.Reviewed by @vasslitvinov - thanks!
Future work
class C : SomeGenericType
-- PR Add a warning for generic superclasses that don't include (?) #22784