Skip to content

Commit

Permalink
chore: add deprecation warnings when casting string/bytes to regex
Browse files Browse the repository at this point in the history
* update .good with deprecation messages for string to regex

Signed-off-by: arezaii <ahmad.rezaii@hpe.com>
  • Loading branch information
arezaii committed Nov 1, 2022
1 parent 3889377 commit 6d3d5c8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/internal/ChapelBase.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,10 @@ module ChapelBase {
// string to a type. Otherwise, we can't resolve chpl_debug_writeln in
// `range.these`
{ var dummyRange = 1..0; for i in dummyRange {} }
return str:t;
if t:string == "regex(string)" || t:string == "regex(bytes)" then
return compile(str);
else
return str:t;
}
}
// param s is used for error reporting
Expand Down
2 changes: 2 additions & 0 deletions modules/standard/Regex.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1142,12 +1142,14 @@ inline operator :(x: regex(bytes), type t: bytes) {

// Cast string to regex
pragma "no doc"
deprecated "Casting strings to regex is deprecated. Use regex.compile(string) instead."
inline operator :(x: string, type t: regex(string)) throws {
return compile(x);
}

// Cast bytes to regex
pragma "no doc"
deprecated "Casting bytes to regex is deprecated. Use regex.compile(bytes) instead."
inline operator :(x: bytes, type t: regex(bytes)) throws {
return compile(x);
}
Expand Down
2 changes: 2 additions & 0 deletions test/deprecated/regexTertiary.good
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
regexTertiary.chpl:8: warning: Casting strings to regex is deprecated. Use regex.compile(string) instead.
regexTertiary.chpl:9: warning: Casting bytes to regex is deprecated. Use regex.compile(bytes) instead.
regexTertiary.chpl:11: warning: string.search is deprecated, use regex search instead
regexTertiary.chpl:12: warning: bytes.search is deprecated, use regex search instead
regexTertiary.chpl:14: warning: string.search is deprecated, use regex search instead
Expand Down
10 changes: 10 additions & 0 deletions test/regex/bytes/cast.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ writeln(b"contains regular expression".find(rb));

writeln("doesn't contain regular expression".find(rs));
writeln(b"doesn't contain regular expression".find(rb));


var rcs = compile(s);
var rcb = compile(b);

writeln("contains regular expression".find(rcs));
writeln(b"contains regular expression".find(rcb));

writeln("doesn't contain regular expression".find(rcs));
writeln(b"doesn't contain regular expression".find(rcb));
6 changes: 6 additions & 0 deletions test/regex/bytes/cast.good
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
cast.chpl:8: warning: Casting strings to regex is deprecated. Use regex.compile(string) instead.
cast.chpl:9: warning: Casting bytes to regex is deprecated. Use regex.compile(bytes) instead.
0
0
-1
-1
0
0
-1
Expand Down

0 comments on commit 6d3d5c8

Please sign in to comment.