10
10
package org .truffleruby .core .cast ;
11
11
12
12
import org .truffleruby .core .hash .RubyHash ;
13
- import org .truffleruby .core .numeric .RubyBignum ;
14
- import org .truffleruby .language .Nil ;
15
13
import org .truffleruby .language .RubyContextSourceNode ;
16
- import org .truffleruby .language .RubyDynamicObject ;
17
14
import org .truffleruby .language .RubyGuards ;
18
15
import org .truffleruby .language .RubyNode ;
19
16
import org .truffleruby .language .control .RaiseException ;
24
21
import com .oracle .truffle .api .frame .VirtualFrame ;
25
22
import com .oracle .truffle .api .profiles .BranchProfile ;
26
23
27
- // TODO(CS): copy and paste of ArrayCastNode
28
24
@ NodeChild (value = "child" , type = RubyNode .class )
29
25
public abstract class HashCastNode extends RubyContextSourceNode {
30
26
31
27
protected abstract RubyNode getChild ();
32
28
33
29
@ Specialization
34
- protected Object cast (boolean value ) {
35
- return nil ;
36
- }
37
-
38
- @ Specialization
39
- protected Object cast (int value ) {
40
- return nil ;
41
- }
42
-
43
- @ Specialization
44
- protected Object cast (long value ) {
45
- return nil ;
46
- }
47
-
48
- @ Specialization
49
- protected Object cast (double value ) {
50
- return nil ;
51
- }
52
-
53
- @ Specialization
54
- protected Object castNil (Nil nil ) {
55
- return nil ;
56
- }
57
-
58
- @ Specialization
59
- protected Object castBignum (RubyBignum value ) {
60
- return nil ;
61
- }
62
-
63
- @ Specialization
64
- protected Object castHash (RubyHash hash ) {
30
+ protected RubyHash castHash (RubyHash hash ) {
65
31
return hash ;
66
32
}
67
33
68
- @ Specialization (guards = { "!isRubyBignum(object)" , "! isRubyHash(object)" } )
69
- protected Object cast (RubyDynamicObject object ,
34
+ @ Specialization (guards = "! isRubyHash(object)" )
35
+ protected RubyHash cast (Object object ,
70
36
@ Cached BranchProfile errorProfile ,
71
37
@ Cached (parameters = "PRIVATE_RETURN_MISSING" ) DispatchNode toHashNode ) {
72
-
73
38
final Object result = toHashNode .call (object , "to_hash" );
39
+
74
40
if (result == DispatchNode .MISSING ) {
75
- return nil ;
41
+ errorProfile .enter ();
42
+ throw new RaiseException (
43
+ getContext (),
44
+ coreExceptions ().typeErrorNoImplicitConversion (object , "Hash" , this ));
76
45
}
77
46
78
47
if (!RubyGuards .isRubyHash (result )) {
@@ -82,7 +51,7 @@ protected Object cast(RubyDynamicObject object,
82
51
coreExceptions ().typeErrorCantConvertTo (object , "Hash" , "to_hash" , result , this ));
83
52
}
84
53
85
- return result ;
54
+ return ( RubyHash ) result ;
86
55
}
87
56
88
57
@ Override
0 commit comments