forked from chapel-lang/chapel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn for generic declared return types without (?) (chapel-lang#23356)
For Cray/chapel-private#5229 / Cray/chapel-private#4736 (comment) Continuing chapel-lang#22745 and chapel-lang#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 (chapel-lang#23355, chapel-lang#23357, chapel-lang#23358); as a result `domain(?)` cannot currently be used as a declared return type. While there, this PR adds checking to fix chapel-lang#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
- Loading branch information
Showing
34 changed files
with
270 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
test/functions/compilation-errors/recursive-generic-return.good
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
recursive-generic-return.chpl:8: warning: please use '?' when declaring a routine with a generic return type | ||
recursive-generic-return.chpl:8: note: for example with 'RR(?)' | ||
recursive-generic-return.chpl:12: warning: RR(int(64)) | ||
recursive-generic-return.chpl:15: warning: please use '?' when declaring a routine with a generic return type | ||
recursive-generic-return.chpl:15: note: for example with 'RR(?)' | ||
recursive-generic-return.chpl:15: error: could not determine the concrete type for the generic return type 'RR' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
record CR { var x: int; } | ||
record GR { type t; var x: t; } | ||
record GRD { type t=int; var x: t; } | ||
class CC { var x: int; } | ||
class GC { type t; var x: t; } | ||
|
||
proc crNoQ(): CR { // OK | ||
return new CR(1); | ||
} | ||
writeln(crNoQ()); | ||
|
||
|
||
proc grNoQ(): GR { // expect a warning | ||
return new GR(int, 1); | ||
} | ||
writeln(grNoQ()); | ||
|
||
proc grQ(): GR(?) { // OK | ||
return new GR(int, 1); | ||
} | ||
writeln(grQ()); | ||
|
||
|
||
proc grdNoQ(): GRD { // OK | ||
return new GRD(int, 1); | ||
} | ||
writeln(grdNoQ()); | ||
|
||
proc grdQ(): GRD(?) { // OK | ||
return new GRD(int, 1); | ||
} | ||
writeln(grdQ()); | ||
|
||
|
||
proc ccNoQ(): CC { // OK | ||
return new CC(1); | ||
} | ||
writeln(ccNoQ()); | ||
|
||
|
||
proc gcNoQ(): GC { // expect a warning | ||
return new GC(int, 1); | ||
} | ||
writeln(gcNoQ()); | ||
|
||
proc gcQ(): GC(?) { // OK | ||
return new GC(int, 1); | ||
} | ||
writeln(gcQ()); | ||
|
Oops, something went wrong.