13
13
import com .oracle .truffle .api .dsl .NeverDefault ;
14
14
import com .oracle .truffle .api .dsl .NodeChild ;
15
15
import com .oracle .truffle .api .dsl .Specialization ;
16
- import com .oracle .truffle .api .profiles .BranchProfile ;
17
16
import org .truffleruby .core .array .RubyArray ;
18
17
import org .truffleruby .language .RubyBaseNodeWithExecute ;
19
- import org .truffleruby .language .control .RaiseException ;
20
18
import org .truffleruby .language .dispatch .DispatchNode ;
21
19
22
20
// Casting of enumerable that is supposed to respond to the #to_a method to RubyArray
@@ -41,33 +39,15 @@ protected RubyArray toA(RubyArray array) {
41
39
return array ;
42
40
}
43
41
44
- @ Specialization (guards = "!isRubyArray(enumerable)" )
45
- protected RubyArray toA (Object enumerable ,
46
- @ Cached BranchProfile errorProfile ,
47
- @ Cached DispatchNode toANode ) {
48
- final Object coerced ;
49
-
50
- try {
51
- coerced = toANode .call (enumerable , "to_a" );
52
- } catch (RaiseException e ) {
53
- errorProfile .enter ();
54
- if (e .getException ().getLogicalClass () == coreLibrary ().noMethodErrorClass ) {
55
- throw new RaiseException (
56
- getContext (),
57
- coreExceptions ().typeErrorCantConvertInto (enumerable , "Array" , this ));
58
- } else {
59
- throw e ;
60
- }
61
- }
62
-
63
- if (!(coerced instanceof RubyArray )) {
64
- errorProfile .enter ();
65
- throw new RaiseException (
66
- getContext (),
67
- coreExceptions ().typeErrorCantConvertTo (enumerable , "Array" , "to_a" , coerced , this ));
68
- }
69
-
70
- return (RubyArray ) coerced ;
42
+ @ Specialization (guards = "!isRubyArray(object)" )
43
+ protected RubyArray coerceObject (Object object ,
44
+ @ Cached DispatchNode toAryNode ) {
45
+ return (RubyArray ) toAryNode .call (
46
+ coreLibrary ().truffleTypeModule ,
47
+ "rb_convert_type" ,
48
+ object ,
49
+ coreLibrary ().arrayClass ,
50
+ coreSymbols ().TO_A );
71
51
}
72
52
73
53
@ Override
0 commit comments