Skip to content

Commit 5c8578a

Browse files
committed
[GR-18163] Coerce the inherit argument to a boolean in Module#{const_defined?,const_get}
PullRequest: truffleruby/2382
2 parents 425d7f8 + 6899b30 commit 5c8578a

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Compatibility:
4646
* Implement `rb_lastline_set` (#2170).
4747
* Implemented `Module#const_source_location` (#2212, @tomstuart and @wildmaples).
4848
* Do not call `File.exist?` in `Dir.glob` as `File.exist?` is often mocked (#2236, @gogainda).
49+
* Coerce the inherit argument to a boolean in `Module#const_defined?` and `Module#const_get` (#2240).
4950

5051
Performance:
5152

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
498498
"ruby-test-specs-linux-11": $.platform.linux + $.jdk.v11 + $.env.jvm + gate_no_build + $.use.build_no_clean + $.run.test_unit_tck + native_config + $.run.clean + $.run.test_specs + { timelimit: "50:00" },
499499
"ruby-test-specs-darwin": $.platform.darwin + $.jdk.v8 + $.env.jvm + gate_no_build + $.use.build_no_clean + $.run.test_unit_tck + native_config + $.run.clean + $.run.test_specs + { timelimit: "01:35:00" },
500500
"ruby-test-specs-darwin-11": $.platform.darwin + $.jdk.v11 + $.env.jvm + gate_no_build + $.use.build_no_clean + $.run.test_unit_tck + native_config + $.run.clean + $.run.test_specs + { timelimit: "01:35:00" },
501-
# "ruby-test-fast-linux-arm64": $.platform.linux_arm64 + $.jdk.v11 + $.env.jvm + gate + $.run.test_fast + native_config + { timelimit: "30:00" }, # GR-29056
501+
"ruby-test-fast-linux-arm64": $.platform.linux_arm64 + $.jdk.v11 + $.env.jvm + gate + $.run.test_fast + native_config + { timelimit: "30:00" },
502502
"ruby-test-fast-linux": $.platform.linux + $.jdk.v8 + $.env.jvm + gate + $.run.test_fast + { timelimit: "30:00" }, # To catch missing slow tags
503503
"ruby-test-mri-linux": $.platform.linux + $.jdk.v8 + $.env.jvm + gate + $.run.test_mri + { timelimit: "45:00" },
504504
"ruby-test-mri-darwin": $.platform.darwin + $.jdk.v8 + $.env.jvm + gate + $.run.test_mri + { timelimit: "01:30:00" },

spec/ruby/core/module/const_defined_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, true).should be_true
4141
end
4242

43+
it "coerces the inherit flag to a boolean" do
44+
ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, nil).should be_false
45+
ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, :true).should be_true
46+
end
47+
4348
it "returns true if the given String names a constant defined in the receiver" do
4449
ConstantSpecs.const_defined?("CS_CONST2").should == true
4550
ConstantSpecs.const_defined?("ModuleA").should == true

spec/ruby/core/module/const_get_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@
8888
end.should raise_error(NameError)
8989
end
9090

91+
it "coerces the inherit flag to a boolean" do
92+
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, :true).should == :const4
93+
94+
-> do
95+
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST1, nil)
96+
end.should raise_error(NameError)
97+
end
98+
9199
it "accepts a toplevel scope qualifier" do
92100
ConstantSpecs.const_get("::CS_CONST1").should == :const1
93101
end

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,11 @@ protected RubyNode coerceToString(RubyNode name) {
941941
return NameToJavaStringNode.create(name);
942942
}
943943

944+
@CreateCast("inherit")
945+
protected RubyNode coerceToBoolean(RubyNode inherit) {
946+
return BooleanCastWithDefaultNodeGen.create(true, inherit);
947+
}
948+
944949
@TruffleBoundary
945950
@Specialization
946951
protected boolean isConstDefined(RubyModule module, String fullName, boolean inherit, boolean checkName) {
@@ -968,6 +973,11 @@ protected RubyNode coerceToSymbolOrString(RubyNode name) {
968973
return ToStringOrSymbolNodeGen.create(name);
969974
}
970975

976+
@CreateCast("inherit")
977+
protected RubyNode coerceToBoolean(RubyNode inherit) {
978+
return BooleanCastWithDefaultNodeGen.create(true, inherit);
979+
}
980+
971981
// Symbol
972982

973983
@Specialization(guards = "inherit")

0 commit comments

Comments
 (0)