Skip to content

Commit 4095e72

Browse files
authored
Deprecate StringLiteral#split(ASTNode) for non-separator arguments (#16439)
1 parent 034a6dc commit 4095e72

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/compiler/crystal/macros.cr

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,24 @@ private macro def_string_methods(klass)
8282
def lines : ArrayLiteral(StringLiteral)
8383
end
8484

85-
# Similar to `String#split`.
85+
# Similar to `String#split()`.
8686
def split : ArrayLiteral(StringLiteral)
8787
end
8888

89-
# Similar to `String#split`.
89+
# Similar to `String#split(String)`.
90+
def split(node : StringLiteral) : ArrayLiteral(StringLiteral)
91+
end
92+
93+
# Similar to `String#split(Char)`.
94+
def split(node : CharLiteral) : ArrayLiteral(StringLiteral)
95+
end
96+
97+
# Similar to `String#split(Regex)`.
98+
def split(node : RegexLiteral) : ArrayLiteral(StringLiteral)
99+
end
100+
101+
# Similar to `String#split(String)`.
102+
@[Deprecated("Use `#split(StringLiteral)` instead")]
90103
def split(node : ASTNode) : ArrayLiteral(StringLiteral)
91104
end
92105

src/compiler/crystal/macros/methods.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ module Crystal
855855
when RegexLiteral
856856
splitter = regex_value(arg)
857857
else
858+
interpreter.warnings.add_warning_at(name_loc, "Deprecated StringLiteral#split(ASTNode). Use `#split(StringLiteral)` instead")
858859
splitter = arg.to_s
859860
end
860861

0 commit comments

Comments
 (0)