Skip to content

Commit bb47827

Browse files
committed
Add new @primitive to warn "block supersedes default value argument"
1 parent 3b8ab34 commit bb47827

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,4 +2041,20 @@ protected Object warn(
20412041

20422042
}
20432043

2044+
@Primitive(name = "warn_block_supersedes_default_value_argument")
2045+
public abstract static class WarnBlockSupersedesDefaultValueArgumentNode extends PrimitiveNode {
2046+
@Specialization
2047+
protected Object warn(
2048+
@Cached("new()") WarnNode warnNode) {
2049+
if (warnNode.shouldWarn()) {
2050+
warnNode.warningMessage(
2051+
getContext().getCallStack().getTopMostUserSourceSection(),
2052+
"block supersedes default value argument");
2053+
}
2054+
2055+
return Nil.INSTANCE;
2056+
}
2057+
2058+
}
2059+
20442060
}

src/main/ruby/truffleruby/core/array.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def fetch(idx, default=undefined)
407407

408408
if idx < 0 or idx >= size
409409
if block_given?
410-
warn 'block supersedes default value argument', uplevel: 1 unless Primitive.undefined?(default)
410+
Primitive.warn_block_supersedes_default_value_argument unless Primitive.undefined?(default)
411411

412412
return yield(orig)
413413
end

src/main/ruby/truffleruby/core/env.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def include?(key)
143143

144144
def fetch(key, absent=undefined)
145145
if block_given? and !Primitive.undefined?(absent)
146-
warn 'block supersedes default value argument', uplevel: 1
146+
Primitive.warn_block_supersedes_default_value_argument
147147
end
148148

149149
if value = lookup(key)

src/main/ruby/truffleruby/core/hash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def fetch(key, default=undefined)
231231
end
232232

233233
if block_given?
234-
warn 'block supersedes default value argument', uplevel: 1 unless Primitive.undefined?(default)
234+
Primitive.warn_block_supersedes_default_value_argument unless Primitive.undefined?(default)
235235

236236
return yield(key)
237237
end

src/main/ruby/truffleruby/core/thread.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def report_on_exception=(val)
223223
end
224224

225225
def fetch(name, default = undefined)
226-
warn 'block supersedes default value argument' if !Primitive.undefined?(default) && block_given?
226+
Primitive.warn_block_supersedes_default_value_argument if !Primitive.undefined?(default) && block_given?
227227

228228
key = convert_to_local_name(name)
229229
locals = Primitive.thread_get_fiber_locals self

src/main/ruby/truffleruby/core/truffle/polyglot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def fetch(key, default = undefined)
156156
end
157157

158158
if block_given?
159-
warn 'block supersedes default value argument', uplevel: 1 unless Primitive.undefined?(default)
159+
Primitive.warn_block_supersedes_default_value_argument unless Primitive.undefined?(default)
160160

161161
return yield(key)
162162
end

0 commit comments

Comments
 (0)