@@ -43,36 +43,36 @@ def access_Binary(o, scope, keys)
4343 def access_String ( o , scope , keys )
4444 keys . flatten!
4545 result = case keys . size
46- when 0
47- fail ( Issues ::BAD_STRING_SLICE_ARITY , @semantic . left_expr , { :actual => keys . size } )
48- when 1
49- # Note that Ruby 1.8.7 requires a length of 1 to produce a String
50- k1 = Utils . to_n ( keys [ 0 ] )
51- bad_string_access_key_type ( o , 0 , k1 . nil? ? keys [ 0 ] : k1 ) unless k1 . is_a? ( Integer )
52- k2 = 1
53- k1 = k1 < 0 ? o . length + k1 : k1 # abs pos
54- # if k1 is outside, a length of 1 always produces an empty string
55- if k1 < 0
56- EMPTY_STRING
57- else
58- o [ k1 , k2 ]
59- end
60- when 2
61- k1 = Utils . to_n ( keys [ 0 ] )
62- k2 = Utils . to_n ( keys [ 1 ] )
63- [ k1 , k2 ] . each_with_index { |k , i | bad_string_access_key_type ( o , i , k . nil? ? keys [ i ] : k ) unless k . is_a? ( Integer ) }
64-
65- k1 = k1 < 0 ? o . length + k1 : k1 # abs pos (negative is count from end)
66- k2 = k2 < 0 ? o . length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count)
67- # if k1 is outside, adjust to first position, and adjust length
68- if k1 < 0
69- k2 = k2 + k1
70- k1 = 0
71- end
72- o [ k1 , k2 ]
73- else
74- fail ( Issues ::BAD_STRING_SLICE_ARITY , @semantic . left_expr , { :actual => keys . size } )
75- end
46+ when 0
47+ fail ( Issues ::BAD_STRING_SLICE_ARITY , @semantic . left_expr , { :actual => keys . size } )
48+ when 1
49+ # Note that Ruby 1.8.7 requires a length of 1 to produce a String
50+ k1 = Utils . to_n ( keys [ 0 ] )
51+ bad_string_access_key_type ( o , 0 , k1 . nil? ? keys [ 0 ] : k1 ) unless k1 . is_a? ( Integer )
52+ k2 = 1
53+ k1 = k1 < 0 ? o . length + k1 : k1 # abs pos
54+ # if k1 is outside, a length of 1 always produces an empty string
55+ if k1 < 0
56+ EMPTY_STRING
57+ else
58+ o [ k1 , k2 ]
59+ end
60+ when 2
61+ k1 = Utils . to_n ( keys [ 0 ] )
62+ k2 = Utils . to_n ( keys [ 1 ] )
63+ [ k1 , k2 ] . each_with_index { |k , i | bad_string_access_key_type ( o , i , k . nil? ? keys [ i ] : k ) unless k . is_a? ( Integer ) }
64+
65+ k1 = k1 < 0 ? o . length + k1 : k1 # abs pos (negative is count from end)
66+ k2 = k2 < 0 ? o . length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count)
67+ # if k1 is outside, adjust to first position, and adjust length
68+ if k1 < 0
69+ k2 = k2 + k1
70+ k1 = 0
71+ end
72+ o [ k1 , k2 ]
73+ else
74+ fail ( Issues ::BAD_STRING_SLICE_ARITY , @semantic . left_expr , { :actual => keys . size } )
75+ end
7676 # Specified as: an index outside of range, or empty result == empty string
7777 ( result . nil? || result . empty? ) ? EMPTY_STRING : result
7878 end
@@ -592,15 +592,15 @@ def access_PResourceType(o, scope, keys)
592592 # type_name is LHS type_name if set, else the first given arg
593593 type_name = o . type_name || Types ::TypeFormatter . singleton . capitalize_segments ( keys . shift )
594594 type_name = case type_name
595- when Types ::PResourceType
596- type_name . type_name
597- when String
598- type_name
599- else
600- # blame given left expression if it defined the type, else the first given key expression
601- blame = o . type_name . nil? ? @semantic . keys [ 0 ] : @semantic . left_expr
602- fail ( Issues ::ILLEGAL_RESOURCE_SPECIALIZATION , blame , { :actual => bad_key_type_name ( type_name ) } )
603- end
595+ when Types ::PResourceType
596+ type_name . type_name
597+ when String
598+ type_name
599+ else
600+ # blame given left expression if it defined the type, else the first given key expression
601+ blame = o . type_name . nil? ? @semantic . keys [ 0 ] : @semantic . left_expr
602+ fail ( Issues ::ILLEGAL_RESOURCE_SPECIALIZATION , blame , { :actual => bad_key_type_name ( type_name ) } )
603+ end
604604
605605 # type name must conform
606606 if type_name !~ Patterns ::CLASSREF_EXT
0 commit comments