Skip to content

Commit 0f97297

Browse files
committed
[GR-31246] Create an assumption per constant
PullRequest: truffleruby/2645
2 parents 950ddf3 + cd85d93 commit 0f97297

File tree

11 files changed

+634
-116
lines changed

11 files changed

+634
-116
lines changed

spec/ruby/core/module/include_spec.rb

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,162 @@ def foo
376376

377377
foo.call.should == 'n'
378378
end
379+
380+
it "updates the constant when an included module is updated" do
381+
module ModuleSpecs::ConstUpdated
382+
module A
383+
FOO = 'a'
384+
end
385+
386+
module M
387+
end
388+
389+
module B
390+
include A
391+
include M
392+
def self.foo
393+
FOO
394+
end
395+
end
396+
397+
B.foo.should == 'a'
398+
399+
M.const_set(:FOO, 'm')
400+
B.foo.should == 'm'
401+
end
402+
end
403+
404+
it "updates the constant when a module included after a call is later updated" do
405+
module ModuleSpecs::ConstLaterUpdated
406+
module A
407+
FOO = 'a'
408+
end
409+
410+
module B
411+
include A
412+
def self.foo
413+
FOO
414+
end
415+
end
416+
417+
B.foo.should == 'a'
418+
419+
module M
420+
end
421+
B.include M
422+
423+
B.foo.should == 'a'
424+
425+
M.const_set(:FOO, 'm')
426+
B.foo.should == 'm'
427+
end
428+
end
429+
430+
it "updates the constant when a module included in another module after a call is later updated" do
431+
module ModuleSpecs::ConstModuleLaterUpdated
432+
module A
433+
FOO = 'a'
434+
end
435+
436+
module B
437+
include A
438+
def self.foo
439+
FOO
440+
end
441+
end
442+
443+
B.foo.should == 'a'
444+
445+
module M
446+
end
447+
B.include M
448+
449+
B.foo.should == 'a'
450+
451+
M.const_set(:FOO, 'm')
452+
B.foo.should == 'm'
453+
end
454+
end
455+
456+
it "updates the constant when a nested included module is updated" do
457+
module ModuleSpecs::ConstUpdatedNestedIncludeUpdated
458+
module A
459+
FOO = 'a'
460+
end
461+
462+
module N
463+
end
464+
465+
module M
466+
include N
467+
end
468+
469+
module B
470+
include A
471+
include M
472+
def self.foo
473+
FOO
474+
end
475+
end
476+
477+
B.foo.should == 'a'
478+
479+
N.const_set(:FOO, 'n')
480+
B.foo.should == 'n'
481+
end
482+
end
483+
484+
it "updates the constant when a new module is included" do
485+
module ModuleSpecs::ConstUpdatedNewInclude
486+
module A
487+
FOO = 'a'
488+
end
489+
490+
module M
491+
FOO = 'm'
492+
end
493+
494+
module B
495+
include A
496+
def self.foo
497+
FOO
498+
end
499+
end
500+
501+
B.foo.should == 'a'
502+
503+
B.include(M)
504+
B.foo.should == 'm'
505+
end
506+
end
507+
508+
it "updates the constant when a new module with nested module is included" do
509+
module ModuleSpecs::ConstUpdatedNestedIncluded
510+
module A
511+
FOO = 'a'
512+
end
513+
514+
module N
515+
FOO = 'n'
516+
end
517+
518+
module M
519+
include N
520+
end
521+
522+
module B
523+
include A
524+
def self.foo
525+
FOO
526+
end
527+
end
528+
529+
B.foo.should == 'a'
530+
531+
B.include M
532+
B.foo.should == 'n'
533+
end
534+
end
379535
end
380536

381537
describe "Module#include?" do

spec/ruby/core/module/prepend_spec.rb

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,191 @@ def foo
222222
foo.call.should == 'n'
223223
end
224224

225+
it "updates the constant when a module is prepended" do
226+
module ModuleSpecs::ConstUpdatePrepended
227+
module M
228+
FOO = 'm'
229+
end
230+
module A
231+
FOO = 'a'
232+
end
233+
module B
234+
include A
235+
def self.foo
236+
FOO
237+
end
238+
end
239+
240+
B.foo.should == 'a'
241+
B.prepend M
242+
B.foo.should == 'm'
243+
end
244+
end
245+
246+
it "updates the constant when a prepended module is updated" do
247+
module ModuleSpecs::ConstPrependedUpdated
248+
module M
249+
end
250+
module A
251+
FOO = 'a'
252+
end
253+
module B
254+
include A
255+
prepend M
256+
def self.foo
257+
FOO
258+
end
259+
end
260+
B.foo.should == 'a'
261+
M.const_set(:FOO, 'm')
262+
B.foo.should == 'm'
263+
end
264+
end
265+
266+
it "updates the constant when there is a base included constant and the prepended module overrides it" do
267+
module ModuleSpecs::ConstIncludedPrependedOverride
268+
module Base
269+
FOO = 'a'
270+
end
271+
module A
272+
include Base
273+
def self.foo
274+
FOO
275+
end
276+
end
277+
A.foo.should == 'a'
278+
279+
module M
280+
FOO = 'm'
281+
end
282+
A.prepend M
283+
A.foo.should == 'm'
284+
end
285+
end
286+
287+
it "updates the constant when there is a base included constant and the prepended module is later updated" do
288+
module ModuleSpecs::ConstIncludedPrependedLaterUpdated
289+
module Base
290+
FOO = 'a'
291+
end
292+
module A
293+
include Base
294+
def self.foo
295+
FOO
296+
end
297+
end
298+
A.foo.should == 'a'
299+
300+
module M
301+
end
302+
A.prepend M
303+
A.foo.should == 'a'
304+
305+
M.const_set(:FOO, 'm')
306+
A.foo.should == 'm'
307+
end
308+
end
309+
310+
it "updates the constant when a module prepended after a constant is later updated" do
311+
module ModuleSpecs::ConstUpdatedPrependedAfterLaterUpdated
312+
module M
313+
end
314+
module A
315+
FOO = 'a'
316+
end
317+
module B
318+
include A
319+
def self.foo
320+
FOO
321+
end
322+
end
323+
B.foo.should == 'a'
324+
325+
B.prepend M
326+
B.foo.should == 'a'
327+
328+
M.const_set(:FOO, 'm')
329+
B.foo.should == 'm'
330+
end
331+
end
332+
333+
it "updates the constant when a module is prepended after another and the constant is defined later on that module" do
334+
module ModuleSpecs::ConstUpdatedPrependedAfterConstDefined
335+
module M
336+
FOO = 'm'
337+
end
338+
module A
339+
prepend M
340+
def self.foo
341+
FOO
342+
end
343+
end
344+
345+
A.foo.should == 'm'
346+
347+
module N
348+
end
349+
A.prepend N
350+
A.foo.should == 'm'
351+
352+
N.const_set(:FOO, 'n')
353+
A.foo.should == 'n'
354+
end
355+
end
356+
357+
it "updates the constant when a module is included in a prepended module and the constant is defined later" do
358+
module ModuleSpecs::ConstUpdatedIncludedInPrependedConstDefinedLater
359+
module A
360+
def self.foo
361+
FOO
362+
end
363+
end
364+
module Base
365+
FOO = 'a'
366+
end
367+
368+
A.prepend Base
369+
A.foo.should == 'a'
370+
371+
module N
372+
end
373+
module M
374+
include N
375+
end
376+
377+
A.prepend M
378+
379+
N.const_set(:FOO, 'n')
380+
A.foo.should == 'n'
381+
end
382+
end
383+
384+
it "updates the constant when a new module with an included module is prepended" do
385+
module ModuleSpecs::ConstUpdatedNewModuleIncludedPrepended
386+
module A
387+
FOO = 'a'
388+
end
389+
module B
390+
include A
391+
def self.foo
392+
FOO
393+
end
394+
end
395+
module N
396+
FOO = 'n'
397+
end
398+
399+
module M
400+
include N
401+
end
402+
403+
B.foo.should == 'a'
404+
405+
B.prepend M
406+
B.foo.should == 'n'
407+
end
408+
end
409+
225410
it "raises a TypeError when the argument is not a Module" do
226411
-> { ModuleSpecs::Basic.prepend(Class.new) }.should raise_error(TypeError)
227412
end

spec/ruby/core/module/remove_const_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,25 @@
8181
ConstantSpecs.autoload :AutoloadedConstant, 'a_file'
8282
ConstantSpecs.send(:remove_const, :AutoloadedConstant).should be_nil
8383
end
84+
85+
it "updates the constant value" do
86+
module ConstantSpecs::RemovedConstantUpdate
87+
module M
88+
FOO = 'm'
89+
end
90+
91+
module A
92+
include M
93+
FOO = 'a'
94+
def self.foo
95+
FOO
96+
end
97+
end
98+
99+
A.foo.should == 'a'
100+
101+
A.send(:remove_const,:FOO)
102+
A.foo.should == 'm'
103+
end
104+
end
84105
end

src/main/java/org/truffleruby/core/CoreLibrary.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ public CoreLibrary(RubyContext context, RubyLanguage language) {
491491
"UnknownKeyException");
492492
defineModule(truffleModule, "CExt");
493493
defineModule(truffleModule, "Debug");
494-
defineModule(truffleModule, "Digest");
495494
defineModule(truffleModule, "ObjSpace");
496495
defineModule(truffleModule, "Coverage");
497496
defineModule(truffleModule, "Graal");

0 commit comments

Comments
 (0)