laser 0.7.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE +661 -0
- data/README.md +158 -0
- data/Rakefile +104 -0
- data/VERSION +1 -0
- data/bin/laser +7 -0
- data/design_docs/goals.md +57 -0
- data/design_docs/object_regex.md +426 -0
- data/design_docs/type_annotations.md +80 -0
- data/ext/laser/BasicBlock.cpp +572 -0
- data/ext/laser/BasicBlock.h +118 -0
- data/ext/laser/extconf.rb +3 -0
- data/features/laser.feature +25 -0
- data/features/step_definitions/laser_steps.rb +39 -0
- data/features/support/env.rb +14 -0
- data/features/support/testdata/1_input +1 -0
- data/features/support/testdata/1_output +1 -0
- data/features/support/testdata/2_input +4 -0
- data/features/support/testdata/2_output +4 -0
- data/features/support/testdata/3_input +8 -0
- data/features/support/testdata/3_output +11 -0
- data/features/support/testdata/4_input +5 -0
- data/features/support/testdata/4_output +5 -0
- data/features/support/testdata/5_input +13 -0
- data/laser.gemspec +382 -0
- data/lib/laser.rb +98 -0
- data/lib/laser/analysis/annotations.rb +95 -0
- data/lib/laser/analysis/annotations/annotation_config.yaml +3 -0
- data/lib/laser/analysis/annotations/comment_attachment_annotation.rb +66 -0
- data/lib/laser/analysis/annotations/node_pointers_annotation.rb +36 -0
- data/lib/laser/analysis/annotations/runtime_annotation.rb +55 -0
- data/lib/laser/analysis/argument_expansion.rb +132 -0
- data/lib/laser/analysis/arity.rb +34 -0
- data/lib/laser/analysis/bindings.rb +144 -0
- data/lib/laser/analysis/bootstrap/bootstrap.rb +298 -0
- data/lib/laser/analysis/bootstrap/laser_class.rb +106 -0
- data/lib/laser/analysis/bootstrap/laser_method.rb +255 -0
- data/lib/laser/analysis/bootstrap/laser_module.rb +403 -0
- data/lib/laser/analysis/bootstrap/laser_module_copy.rb +74 -0
- data/lib/laser/analysis/bootstrap/laser_object.rb +69 -0
- data/lib/laser/analysis/bootstrap/laser_proc.rb +150 -0
- data/lib/laser/analysis/bootstrap/laser_singleton_class.rb +44 -0
- data/lib/laser/analysis/comments.rb +35 -0
- data/lib/laser/analysis/control_flow.rb +28 -0
- data/lib/laser/analysis/control_flow/alias_analysis.rb +31 -0
- data/lib/laser/analysis/control_flow/basic_block.rb +105 -0
- data/lib/laser/analysis/control_flow/cfg_builder.rb +2505 -0
- data/lib/laser/analysis/control_flow/cfg_instruction.rb +190 -0
- data/lib/laser/analysis/control_flow/constant_propagation.rb +742 -0
- data/lib/laser/analysis/control_flow/control_flow_graph.rb +370 -0
- data/lib/laser/analysis/control_flow/lifetime_analysis.rb +91 -0
- data/lib/laser/analysis/control_flow/method_call_search.rb +26 -0
- data/lib/laser/analysis/control_flow/raise_properties.rb +25 -0
- data/lib/laser/analysis/control_flow/simulation.rb +385 -0
- data/lib/laser/analysis/control_flow/static_single_assignment.rb +185 -0
- data/lib/laser/analysis/control_flow/unreachability_analysis.rb +57 -0
- data/lib/laser/analysis/control_flow/unused_variables.rb +91 -0
- data/lib/laser/analysis/control_flow/yield_properties.rb +103 -0
- data/lib/laser/analysis/errors.rb +131 -0
- data/lib/laser/analysis/laser_utils.rb +18 -0
- data/lib/laser/analysis/lexical_analysis.rb +172 -0
- data/lib/laser/analysis/method_call.rb +68 -0
- data/lib/laser/analysis/protocol_registry.rb +30 -0
- data/lib/laser/analysis/scope.rb +118 -0
- data/lib/laser/analysis/sexp.rb +159 -0
- data/lib/laser/analysis/sexp_analysis.rb +40 -0
- data/lib/laser/analysis/sexp_extensions/constant_extraction.rb +115 -0
- data/lib/laser/analysis/sexp_extensions/source_location.rb +164 -0
- data/lib/laser/analysis/sexp_extensions/type_inference.rb +47 -0
- data/lib/laser/analysis/signature.rb +76 -0
- data/lib/laser/analysis/special_methods/send.rb +67 -0
- data/lib/laser/analysis/unused_methods.rb +21 -0
- data/lib/laser/analysis/visitor.rb +141 -0
- data/lib/laser/annotation_parser/annotations.treetop +126 -0
- data/lib/laser/annotation_parser/annotations_parser.rb +748 -0
- data/lib/laser/annotation_parser/class_annotations.treetop +82 -0
- data/lib/laser/annotation_parser/class_annotations_parser.rb +654 -0
- data/lib/laser/annotation_parser/overload.treetop +24 -0
- data/lib/laser/annotation_parser/overload_parser.rb +167 -0
- data/lib/laser/annotation_parser/parsers.rb +6 -0
- data/lib/laser/annotation_parser/structural.treetop +37 -0
- data/lib/laser/annotation_parser/structural_parser.rb +406 -0
- data/lib/laser/annotation_parser/useful_parsers.treetop +47 -0
- data/lib/laser/annotation_parser/useful_parsers_parser.rb +674 -0
- data/lib/laser/rake/task.rb +46 -0
- data/lib/laser/runner.rb +189 -0
- data/lib/laser/scanner.rb +169 -0
- data/lib/laser/standard_library/_thread.rb +110 -0
- data/lib/laser/standard_library/abbrev.rb +103 -0
- data/lib/laser/standard_library/array.rb +418 -0
- data/lib/laser/standard_library/base64.rb +91 -0
- data/lib/laser/standard_library/basic_object.rb +55 -0
- data/lib/laser/standard_library/benchmark.rb +556 -0
- data/lib/laser/standard_library/bignum.rb +185 -0
- data/lib/laser/standard_library/cgi.rb +275 -0
- data/lib/laser/standard_library/cgi/cookie.rb +147 -0
- data/lib/laser/standard_library/cgi/core.rb +791 -0
- data/lib/laser/standard_library/cgi/html.rb +1021 -0
- data/lib/laser/standard_library/cgi/session.rb +537 -0
- data/lib/laser/standard_library/cgi/session/pstore.rb +111 -0
- data/lib/laser/standard_library/cgi/util.rb +188 -0
- data/lib/laser/standard_library/class_definitions.rb +333 -0
- data/lib/laser/standard_library/comparable.rb +125 -0
- data/lib/laser/standard_library/complex.rb +162 -0
- data/lib/laser/standard_library/enumerable.rb +178 -0
- data/lib/laser/standard_library/exceptions.rb +135 -0
- data/lib/laser/standard_library/fixnum.rb +188 -0
- data/lib/laser/standard_library/float.rb +180 -0
- data/lib/laser/standard_library/hash.rb +237 -0
- data/lib/laser/standard_library/integer.rb +123 -0
- data/lib/laser/standard_library/laser_magic.rb +7 -0
- data/lib/laser/standard_library/nil_false_true.rb +113 -0
- data/lib/laser/standard_library/numbers.rb +192 -0
- data/lib/laser/standard_library/proc.rb +31 -0
- data/lib/laser/standard_library/set.rb +1348 -0
- data/lib/laser/standard_library/string.rb +666 -0
- data/lib/laser/standard_library/stringio.rb +2 -0
- data/lib/laser/standard_library/symbol.rb +125 -0
- data/lib/laser/standard_library/tsort.rb +242 -0
- data/lib/laser/support/acts_as_struct.rb +66 -0
- data/lib/laser/support/frequency.rb +55 -0
- data/lib/laser/support/inheritable_attributes.rb +145 -0
- data/lib/laser/support/module_extensions.rb +94 -0
- data/lib/laser/support/placeholder_object.rb +13 -0
- data/lib/laser/third_party/rgl/adjacency.rb +221 -0
- data/lib/laser/third_party/rgl/base.rb +228 -0
- data/lib/laser/third_party/rgl/bidirectional.rb +39 -0
- data/lib/laser/third_party/rgl/condensation.rb +47 -0
- data/lib/laser/third_party/rgl/connected_components.rb +138 -0
- data/lib/laser/third_party/rgl/control_flow.rb +170 -0
- data/lib/laser/third_party/rgl/depth_first_spanning_tree.rb +37 -0
- data/lib/laser/third_party/rgl/dominators.rb +124 -0
- data/lib/laser/third_party/rgl/dot.rb +93 -0
- data/lib/laser/third_party/rgl/graphxml.rb +51 -0
- data/lib/laser/third_party/rgl/implicit.rb +174 -0
- data/lib/laser/third_party/rgl/mutable.rb +117 -0
- data/lib/laser/third_party/rgl/rdot.rb +445 -0
- data/lib/laser/third_party/rgl/topsort.rb +72 -0
- data/lib/laser/third_party/rgl/transitivity.rb +180 -0
- data/lib/laser/third_party/rgl/traversal.rb +348 -0
- data/lib/laser/types/types.rb +433 -0
- data/lib/laser/version.rb +14 -0
- data/lib/laser/warning.rb +149 -0
- data/lib/laser/warning_sets/default.yml +13 -0
- data/lib/laser/warnings/assignment_in_condition.rb +20 -0
- data/lib/laser/warnings/comment_spacing.rb +31 -0
- data/lib/laser/warnings/extra_blank_lines.rb +30 -0
- data/lib/laser/warnings/extra_whitespace.rb +16 -0
- data/lib/laser/warnings/hash_symbol_18_warning.rb +63 -0
- data/lib/laser/warnings/hash_symbol_19_warning.rb +29 -0
- data/lib/laser/warnings/line_length.rb +115 -0
- data/lib/laser/warnings/misaligned_unindentation.rb +17 -0
- data/lib/laser/warnings/operator_spacing.rb +68 -0
- data/lib/laser/warnings/parens_on_declaration.rb +30 -0
- data/lib/laser/warnings/rescue_exception.rb +42 -0
- data/lib/laser/warnings/semicolon.rb +25 -0
- data/lib/laser/warnings/sexp_errors.rb +24 -0
- data/lib/laser/warnings/uncalled_method_warning.rb +7 -0
- data/lib/laser/warnings/useless_double_quotes.rb +38 -0
- data/spec/analysis_specs/annotations_spec.rb +47 -0
- data/spec/analysis_specs/annotations_specs/comment_attachment_spec.rb +68 -0
- data/spec/analysis_specs/annotations_specs/node_pointers_annotation_spec.rb +90 -0
- data/spec/analysis_specs/annotations_specs/runtime_annotation_spec.rb +135 -0
- data/spec/analysis_specs/annotations_specs/spec_helper.rb +33 -0
- data/spec/analysis_specs/argument_expansion_spec.rb +113 -0
- data/spec/analysis_specs/bindings_spec.rb +36 -0
- data/spec/analysis_specs/comment_spec.rb +93 -0
- data/spec/analysis_specs/control_flow_specs/cfg_instruction_spec.rb +111 -0
- data/spec/analysis_specs/control_flow_specs/constant_propagation_spec.rb +560 -0
- data/spec/analysis_specs/control_flow_specs/control_flow_graph_spec.rb +5 -0
- data/spec/analysis_specs/control_flow_specs/raise_properties_spec.rb +310 -0
- data/spec/analysis_specs/control_flow_specs/raise_type_inference_spec.rb +301 -0
- data/spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb +431 -0
- data/spec/analysis_specs/control_flow_specs/simulation_spec.rb +158 -0
- data/spec/analysis_specs/control_flow_specs/spec_helper.rb +110 -0
- data/spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb +125 -0
- data/spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb +76 -0
- data/spec/analysis_specs/control_flow_specs/unused_variable_spec.rb +99 -0
- data/spec/analysis_specs/control_flow_specs/yield_properties_spec.rb +372 -0
- data/spec/analysis_specs/error_spec.rb +30 -0
- data/spec/analysis_specs/laser_class_spec.rb +322 -0
- data/spec/analysis_specs/lexical_analysis_spec.rb +184 -0
- data/spec/analysis_specs/protocol_registry_spec.rb +63 -0
- data/spec/analysis_specs/scope_annotation_spec.rb +1013 -0
- data/spec/analysis_specs/scope_spec.rb +126 -0
- data/spec/analysis_specs/sexp_analysis_spec.rb +30 -0
- data/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +309 -0
- data/spec/analysis_specs/sexp_extension_specs/source_location_spec.rb +231 -0
- data/spec/analysis_specs/sexp_extension_specs/spec_helper.rb +1 -0
- data/spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb +252 -0
- data/spec/analysis_specs/sexp_spec.rb +167 -0
- data/spec/analysis_specs/spec_helper.rb +27 -0
- data/spec/analysis_specs/unused_methods_spec.rb +65 -0
- data/spec/analysis_specs/visitor_spec.rb +64 -0
- data/spec/annotation_parser_specs/annotations_parser_spec.rb +89 -0
- data/spec/annotation_parser_specs/class_annotation_parser_spec.rb +120 -0
- data/spec/annotation_parser_specs/overload_parser_spec.rb +39 -0
- data/spec/annotation_parser_specs/parsers_spec.rb +14 -0
- data/spec/annotation_parser_specs/spec_helper.rb +1 -0
- data/spec/annotation_parser_specs/structural_parser_spec.rb +67 -0
- data/spec/laser_spec.rb +14 -0
- data/spec/rake_specs/spec_helper.rb +1 -0
- data/spec/rake_specs/task_spec.rb +67 -0
- data/spec/runner_spec.rb +207 -0
- data/spec/scanner_spec.rb +75 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/standard_library/exceptions_spec.rb +19 -0
- data/spec/standard_library/globals_spec.rb +14 -0
- data/spec/standard_library/set_spec.rb +31 -0
- data/spec/standard_library/spec_helper.rb +1 -0
- data/spec/standard_library/standard_library_spec.rb +302 -0
- data/spec/support_specs/acts_as_struct_spec.rb +94 -0
- data/spec/support_specs/frequency_spec.rb +23 -0
- data/spec/support_specs/module_extensions_spec.rb +117 -0
- data/spec/support_specs/spec_helper.rb +1 -0
- data/spec/type_specs/spec_helper.rb +1 -0
- data/spec/type_specs/types_spec.rb +133 -0
- data/spec/warning_spec.rb +95 -0
- data/spec/warning_specs/assignment_in_condition_spec.rb +68 -0
- data/spec/warning_specs/comment_spacing_spec.rb +65 -0
- data/spec/warning_specs/extra_blank_lines_spec.rb +70 -0
- data/spec/warning_specs/extra_whitespace_spec.rb +33 -0
- data/spec/warning_specs/hash_symbol_18_warning_spec.rb +89 -0
- data/spec/warning_specs/hash_symbol_19_warning_spec.rb +63 -0
- data/spec/warning_specs/line_length_spec.rb +173 -0
- data/spec/warning_specs/misaligned_unindentation_spec.rb +35 -0
- data/spec/warning_specs/operator_spacing_spec.rb +104 -0
- data/spec/warning_specs/parens_on_declaration_spec.rb +57 -0
- data/spec/warning_specs/rescue_exception_spec.rb +105 -0
- data/spec/warning_specs/semicolon_spec.rb +58 -0
- data/spec/warning_specs/spec_helper.rb +1 -0
- data/spec/warning_specs/useless_double_quotes_spec.rb +74 -0
- data/status_reports/2010/12/2010-12-14.md +163 -0
- data/status_reports/2010/12/2010-12-23.md +298 -0
- data/status_reports/2010/12/2010-12-24.md +6 -0
- data/test/third_party_tests/rgl_tests/TestComponents.rb +65 -0
- data/test/third_party_tests/rgl_tests/TestCycles.rb +61 -0
- data/test/third_party_tests/rgl_tests/TestDirectedGraph.rb +125 -0
- data/test/third_party_tests/rgl_tests/TestDot.rb +18 -0
- data/test/third_party_tests/rgl_tests/TestEdge.rb +34 -0
- data/test/third_party_tests/rgl_tests/TestGraph.rb +71 -0
- data/test/third_party_tests/rgl_tests/TestGraphXML.rb +57 -0
- data/test/third_party_tests/rgl_tests/TestImplicit.rb +52 -0
- data/test/third_party_tests/rgl_tests/TestRdot.rb +863 -0
- data/test/third_party_tests/rgl_tests/TestTransitivity.rb +129 -0
- data/test/third_party_tests/rgl_tests/TestTraversal.rb +220 -0
- data/test/third_party_tests/rgl_tests/TestUnDirectedGraph.rb +102 -0
- data/test/third_party_tests/rgl_tests/examples/north/Graph.log +128 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.0.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.1.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.11.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.12.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.13.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.14.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.15.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.16.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.17.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.19.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.2.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.20.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.22.graphml +43 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.24.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.25.graphml +45 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.27.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.28.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.29.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.3.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.30.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.31.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.34.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.37.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.38.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.39.graphml +36 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.4.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.40.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.41.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.42.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.45.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.46.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.5.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.50.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.56.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.57.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.58.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.6.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.60.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.61.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.62.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.68.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.69.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.7.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.70.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.71.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.72.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.74.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.75.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.78.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.79.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.8.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.80.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.82.graphml +35 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.83.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.85.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.86.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.88.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.89.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.9.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.90.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.91.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.92.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.93.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.94.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.12.8.graphml +40 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.14.9.graphml +36 -0
- data/test/third_party_tests/rgl_tests/test_helper.rb +7 -0
- data/test/third_party_tests/test_inheritable_attributes.rb +187 -0
- metadata +470 -0
@@ -0,0 +1,310 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe ControlFlow::RaiseProperties do
|
4
|
+
it 'should recognize simple methods that raise no exceptions due to constants' do
|
5
|
+
g = cfg_method <<-EOF
|
6
|
+
def foo(x)
|
7
|
+
y = 'hello' * 2
|
8
|
+
p(y)
|
9
|
+
y.singleton_class
|
10
|
+
end
|
11
|
+
EOF
|
12
|
+
g.raise_frequency.should be Frequency::NEVER
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should recognize simple methods that unconditionally raise' do
|
16
|
+
g = cfg_method <<-EOF
|
17
|
+
def foo(x)
|
18
|
+
raise SomeError.new(x)
|
19
|
+
end
|
20
|
+
EOF
|
21
|
+
g.raise_frequency.should be Frequency::ALWAYS
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should recognize raiseability via aliases' do
|
25
|
+
g = cfg_method <<-EOF
|
26
|
+
def foo(x)
|
27
|
+
fail SomeError.new(x)
|
28
|
+
end
|
29
|
+
EOF
|
30
|
+
g.raise_frequency.should be Frequency::ALWAYS
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should recognize simple methods that might raise' do
|
34
|
+
g = cfg_method <<-EOF
|
35
|
+
def foo(x)
|
36
|
+
if gets # may raise
|
37
|
+
'hi'
|
38
|
+
else
|
39
|
+
'there'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
EOF
|
43
|
+
g.raise_frequency.should be Frequency::MAYBE
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should recognize when private methods are called' do
|
47
|
+
g = cfg_method <<-EOF
|
48
|
+
def foo(x)
|
49
|
+
String.alias_method(:bar, :<<)
|
50
|
+
end
|
51
|
+
EOF
|
52
|
+
g.raise_frequency.should be Frequency::ALWAYS
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should use types to improve raising inference on user code' do
|
56
|
+
g = cfg <<-EOF
|
57
|
+
module RInfer1
|
58
|
+
def self.multiply(x)
|
59
|
+
check_and_mult(x)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.check_and_mult(y)
|
63
|
+
if String === y
|
64
|
+
raise 'no strings!'
|
65
|
+
end
|
66
|
+
p(y)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
EOF
|
70
|
+
method = ClassRegistry['RInfer1'].singleton_class.instance_method(:multiply)
|
71
|
+
method.raise_frequency_for_types(
|
72
|
+
Utilities.type_for(ClassRegistry['RInfer1']),
|
73
|
+
[Types::FIXNUM],
|
74
|
+
Types::NILCLASS).should == Frequency::NEVER
|
75
|
+
method.raise_frequency_for_types(
|
76
|
+
Utilities.type_for(ClassRegistry['RInfer1']),
|
77
|
+
[Types::STRING],
|
78
|
+
Types::NILCLASS).should == Frequency::ALWAYS
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should infer raises from #initialize when calling Class.new' do
|
82
|
+
g = cfg <<-EOF
|
83
|
+
class RInfer2
|
84
|
+
def initialize(x)
|
85
|
+
raise TypeError.new("I don't like integers") if Integer === x
|
86
|
+
end
|
87
|
+
end
|
88
|
+
def make_rinfer_2(x)
|
89
|
+
RInfer2.new(x)
|
90
|
+
end
|
91
|
+
EOF
|
92
|
+
method = ClassRegistry['Object'].instance_method(:make_rinfer_2)
|
93
|
+
# call make_rinfer_2 should raise for a fixnum
|
94
|
+
method.raise_frequency_for_types(
|
95
|
+
Types::STRING, # doesn't matter
|
96
|
+
[Types::FIXNUM],
|
97
|
+
Types::NILCLASS).should == Frequency::ALWAYS
|
98
|
+
method.raise_frequency_for_types(
|
99
|
+
Types::STRING, # doesn't matter
|
100
|
+
[ClassRegistry['Bignum'].as_type],
|
101
|
+
Types::NILCLASS).should == Frequency::ALWAYS
|
102
|
+
method.raise_frequency_for_types(
|
103
|
+
Types::STRING, # doesn't matter
|
104
|
+
[Types::STRING],
|
105
|
+
Types::NILCLASS).should == Frequency::NEVER
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should infer a potential raises by argument type' do
|
109
|
+
g = cfg <<-EOF
|
110
|
+
class RInfer3
|
111
|
+
def initialize(x)
|
112
|
+
try_to_foo(x) if x != 0
|
113
|
+
end
|
114
|
+
|
115
|
+
def try_to_foo(x)
|
116
|
+
case x
|
117
|
+
when Integer
|
118
|
+
raise ArgumentError.new('no negative numbers') if x < 0
|
119
|
+
when Float
|
120
|
+
raise TypeError.new('no floats at all')
|
121
|
+
else
|
122
|
+
x.ljust(20)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
def make_RInfer_3(x)
|
127
|
+
RInfer3.new(x)
|
128
|
+
end
|
129
|
+
EOF
|
130
|
+
method = ClassRegistry['Object'].instance_method(:make_RInfer_3)
|
131
|
+
# call make_rinfer_2 should raise for a fixnum
|
132
|
+
method.raise_frequency_for_types(
|
133
|
+
Types::STRING, # doesn't matter
|
134
|
+
[Types::FLOAT],
|
135
|
+
Types::NILCLASS).should == Frequency::MAYBE
|
136
|
+
method.raise_frequency_for_types(
|
137
|
+
Types::STRING, # doesn't matter
|
138
|
+
[ClassRegistry['Bignum'].as_type],
|
139
|
+
Types::NILCLASS).should == Frequency::MAYBE
|
140
|
+
method.raise_frequency_for_types(
|
141
|
+
Types::STRING, # doesn't matter
|
142
|
+
[Types::ARRAY],
|
143
|
+
Types::NILCLASS).should == Frequency::MAYBE # not smart enough to prove != 0 yet
|
144
|
+
method.raise_frequency_for_types(
|
145
|
+
Types::STRING, # doesn't matter
|
146
|
+
[Types::STRING],
|
147
|
+
Types::NILCLASS).should == Frequency::NEVER
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'can infer raises from calls to the annotated String class' do
|
151
|
+
g = cfg <<-EOF
|
152
|
+
class RInfer4
|
153
|
+
def silly(x)
|
154
|
+
x.getbyte(x.size * 2)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
EOF
|
158
|
+
method = ClassRegistry['RInfer4'].instance_method(:silly)
|
159
|
+
method.raise_frequency_for_types(
|
160
|
+
Utilities.type_for(ClassRegistry['RInfer4']),
|
161
|
+
[Types::STRING],
|
162
|
+
Types::NILCLASS).should == Frequency::MAYBE
|
163
|
+
method.raise_frequency_for_types(
|
164
|
+
Utilities.type_for(ClassRegistry['RInfer4']),
|
165
|
+
[Types::FIXNUM],
|
166
|
+
Types::NILCLASS).should == Frequency::ALWAYS
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'can infer a guaranteed NoMethodError from privacy violations' do
|
170
|
+
g = cfg <<-EOF
|
171
|
+
class RInfer5
|
172
|
+
def foo
|
173
|
+
end
|
174
|
+
private :foo
|
175
|
+
|
176
|
+
def bar
|
177
|
+
self.foo # error!
|
178
|
+
end
|
179
|
+
end
|
180
|
+
EOF
|
181
|
+
method = ClassRegistry['RInfer5'].instance_method(:bar)
|
182
|
+
method.raise_frequency_for_types(
|
183
|
+
Utilities.type_for(ClassRegistry['RInfer5'])).should == Frequency::ALWAYS
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'can infer a potential lookup failure when a successful one exists' do
|
187
|
+
g = cfg <<-EOF
|
188
|
+
class RInfer6
|
189
|
+
def bar
|
190
|
+
if gets.size > 0
|
191
|
+
x = 'hello'
|
192
|
+
else
|
193
|
+
x = 5
|
194
|
+
end
|
195
|
+
x.intern # error sometimes
|
196
|
+
end
|
197
|
+
end
|
198
|
+
EOF
|
199
|
+
method = ClassRegistry['RInfer6'].instance_method(:bar)
|
200
|
+
method.raise_frequency_for_types(
|
201
|
+
Utilities.type_for(ClassRegistry['RInfer6'])).should == Frequency::MAYBE
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'can infer an ArgumentError when invalid arities are given' do
|
205
|
+
g = cfg <<-EOF
|
206
|
+
class RInfer7
|
207
|
+
def foo(*args)
|
208
|
+
bar(*args)
|
209
|
+
end
|
210
|
+
def bar(a, b=1, c=2, d)
|
211
|
+
a
|
212
|
+
end
|
213
|
+
end
|
214
|
+
EOF
|
215
|
+
method = ClassRegistry['RInfer7'].instance_method(:foo)
|
216
|
+
method.raise_frequency_for_types(
|
217
|
+
ClassRegistry['RInfer7'].as_type).should == Frequency::ALWAYS
|
218
|
+
method.raise_frequency_for_types(
|
219
|
+
ClassRegistry['RInfer7'].as_type,
|
220
|
+
[Types::STRING]).should == Frequency::ALWAYS
|
221
|
+
method.raise_frequency_for_types(
|
222
|
+
ClassRegistry['RInfer7'].as_type,
|
223
|
+
[Types::STRING, Types::FIXNUM]).should == Frequency::NEVER
|
224
|
+
method.raise_frequency_for_types(
|
225
|
+
ClassRegistry['RInfer7'].as_type,
|
226
|
+
[Types::STRING, Types::FIXNUM,
|
227
|
+
Types::BIGNUM]).should == Frequency::NEVER
|
228
|
+
method.raise_frequency_for_types(
|
229
|
+
ClassRegistry['RInfer7'].as_type,
|
230
|
+
[Types::STRING, Types::FIXNUM,
|
231
|
+
Types::BIGNUM, Types::ARRAY]).should == Frequency::NEVER
|
232
|
+
method.raise_frequency_for_types(
|
233
|
+
ClassRegistry['RInfer7'].as_type,
|
234
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM,
|
235
|
+
Types::ARRAY, Types::HASH]).should == Frequency::ALWAYS
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'can infer guaranteed errors when super provides incorrect arities' do
|
239
|
+
g = cfg <<-EOF
|
240
|
+
class RInfer8
|
241
|
+
def foo(a, b=1, c=2, d)
|
242
|
+
a
|
243
|
+
end
|
244
|
+
end
|
245
|
+
class RInfer8B < RInfer8
|
246
|
+
def foo(*args)
|
247
|
+
super(*args)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
EOF
|
251
|
+
method = ClassRegistry['RInfer8B'].instance_method(:foo)
|
252
|
+
method.raise_frequency_for_types(
|
253
|
+
ClassRegistry['RInfer8B'].as_type).should == Frequency::ALWAYS
|
254
|
+
method.raise_frequency_for_types(
|
255
|
+
ClassRegistry['RInfer8B'].as_type,
|
256
|
+
[Types::STRING]).should == Frequency::ALWAYS
|
257
|
+
method.raise_frequency_for_types(
|
258
|
+
ClassRegistry['RInfer8B'].as_type,
|
259
|
+
[Types::STRING, Types::FIXNUM]).should == Frequency::NEVER
|
260
|
+
method.raise_frequency_for_types(
|
261
|
+
ClassRegistry['RInfer8B'].as_type,
|
262
|
+
[Types::STRING, Types::FIXNUM,
|
263
|
+
Types::BIGNUM]).should == Frequency::NEVER
|
264
|
+
method.raise_frequency_for_types(
|
265
|
+
ClassRegistry['RInfer8B'].as_type,
|
266
|
+
[Types::STRING, Types::FIXNUM,
|
267
|
+
Types::BIGNUM, Types::ARRAY]).should == Frequency::NEVER
|
268
|
+
method.raise_frequency_for_types(
|
269
|
+
ClassRegistry['RInfer8B'].as_type,
|
270
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM,
|
271
|
+
Types::ARRAY, Types::HASH]).should == Frequency::ALWAYS
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'can infer guaranteed errors when zsuper provides incorrect arities' do
|
275
|
+
g = cfg <<-EOF
|
276
|
+
class RInfer9
|
277
|
+
def foo(a, b=1, c=2, d)
|
278
|
+
a
|
279
|
+
end
|
280
|
+
end
|
281
|
+
class RInfer9B < RInfer9
|
282
|
+
def foo(*args)
|
283
|
+
super
|
284
|
+
end
|
285
|
+
end
|
286
|
+
EOF
|
287
|
+
method = ClassRegistry['RInfer9B'].instance_method(:foo)
|
288
|
+
method.raise_frequency_for_types(
|
289
|
+
ClassRegistry['RInfer9B'].as_type).should == Frequency::ALWAYS
|
290
|
+
method.raise_frequency_for_types(
|
291
|
+
ClassRegistry['RInfer9B'].as_type,
|
292
|
+
[Types::STRING]).should == Frequency::ALWAYS
|
293
|
+
method.raise_frequency_for_types(
|
294
|
+
ClassRegistry['RInfer9B'].as_type,
|
295
|
+
[Types::STRING, Types::FIXNUM]).should == Frequency::NEVER
|
296
|
+
method.raise_frequency_for_types(
|
297
|
+
ClassRegistry['RInfer9B'].as_type,
|
298
|
+
[Types::STRING, Types::FIXNUM,
|
299
|
+
Types::BIGNUM]).should == Frequency::NEVER
|
300
|
+
method.raise_frequency_for_types(
|
301
|
+
ClassRegistry['RInfer9B'].as_type,
|
302
|
+
[Types::STRING, Types::FIXNUM,
|
303
|
+
Types::BIGNUM, Types::ARRAY]).should == Frequency::NEVER
|
304
|
+
method.raise_frequency_for_types(
|
305
|
+
ClassRegistry['RInfer9B'].as_type,
|
306
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM,
|
307
|
+
Types::ARRAY, Types::HASH]).should == Frequency::ALWAYS
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
@@ -0,0 +1,301 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CFG-based raise type inference' do
|
4
|
+
it 'should infer types based on specified overloads' do
|
5
|
+
g = cfg <<-EOF
|
6
|
+
class RI1
|
7
|
+
def tap_10
|
8
|
+
yield 10
|
9
|
+
10
|
10
|
+
end
|
11
|
+
end
|
12
|
+
EOF
|
13
|
+
method = ClassRegistry['RI1'].instance_method(:tap_10)
|
14
|
+
method.raise_type_for_types(
|
15
|
+
Utilities.type_for(ClassRegistry['RI1'])).should equal_type(
|
16
|
+
Types::UnionType.new([Types::ClassType.new('LocalJumpError', :invariant)]))
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should infer types based on raising a string' do
|
20
|
+
g = cfg <<-EOF
|
21
|
+
class RI2
|
22
|
+
def raise_string
|
23
|
+
raise 'foo'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
EOF
|
27
|
+
method = ClassRegistry['RI2'].instance_method(:raise_string)
|
28
|
+
method.raise_type_for_types(
|
29
|
+
Utilities.type_for(ClassRegistry['RI2'])).should equal_type(
|
30
|
+
Types::UnionType.new([Types::ClassType.new('RuntimeError', :invariant)]))
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should infer types based on raising an Exception class' do
|
34
|
+
g = cfg <<-EOF
|
35
|
+
class RI3
|
36
|
+
def raise_class
|
37
|
+
raise TypeError
|
38
|
+
end
|
39
|
+
end
|
40
|
+
EOF
|
41
|
+
method = ClassRegistry['RI3'].instance_method(:raise_class)
|
42
|
+
method.raise_type_for_types(
|
43
|
+
Utilities.type_for(ClassRegistry['RI3'])).should equal_type(
|
44
|
+
Types::UnionType.new([Types::ClassType.new('TypeError', :invariant)]))
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should infer types based on raising an Exception instance' do
|
48
|
+
g = cfg <<-EOF
|
49
|
+
class RI4
|
50
|
+
def raise_instance
|
51
|
+
raise ArgumentError.new('foo')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
EOF
|
55
|
+
method = ClassRegistry['RI4'].instance_method(:raise_instance)
|
56
|
+
method.raise_type_for_types(
|
57
|
+
Utilities.type_for(ClassRegistry['RI4'])).should equal_type(
|
58
|
+
Types::UnionType.new([Types::ClassType.new('ArgumentError', :invariant)]))
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should infer raises from #initialize when calling Class.new' do
|
62
|
+
g = cfg <<-EOF
|
63
|
+
class RTInfer2
|
64
|
+
def initialize(x)
|
65
|
+
raise TypeError.new("I don't like integers") if Integer === x
|
66
|
+
end
|
67
|
+
end
|
68
|
+
def make_rtinfer_2(x)
|
69
|
+
RTInfer2.new(x)
|
70
|
+
end
|
71
|
+
EOF
|
72
|
+
method = ClassRegistry['Object'].instance_method(:make_rtinfer_2)
|
73
|
+
# call make_rinfer_2 should raise for a fixnum
|
74
|
+
method.raise_type_for_types(
|
75
|
+
Types::STRING, # doesn't matter
|
76
|
+
[Types::FIXNUM],
|
77
|
+
Types::NILCLASS).should equal_type(ClassRegistry['TypeError'].as_type)
|
78
|
+
method.raise_type_for_types(
|
79
|
+
Types::STRING, # doesn't matter
|
80
|
+
[ClassRegistry['Bignum'].as_type],
|
81
|
+
Types::NILCLASS).should equal_type(ClassRegistry['TypeError'].as_type)
|
82
|
+
method.raise_type_for_types(
|
83
|
+
Types::STRING, # doesn't matter
|
84
|
+
[Types::STRING],
|
85
|
+
Types::NILCLASS).should equal_type(Types::EMPTY)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should infer a potential raises by argument type' do
|
89
|
+
g = cfg <<-EOF
|
90
|
+
class RTInfer3
|
91
|
+
def initialize(x)
|
92
|
+
try_to_foo(x) if x != 0
|
93
|
+
end
|
94
|
+
|
95
|
+
def try_to_foo(x)
|
96
|
+
case x
|
97
|
+
when Integer
|
98
|
+
raise ArgumentError.new('no negative numbers') if x < 0
|
99
|
+
when Float
|
100
|
+
raise TypeError.new('no floats at all')
|
101
|
+
else
|
102
|
+
x.ljust(20)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
def make_rtinfer_3(x)
|
107
|
+
RTInfer3.new(x)
|
108
|
+
end
|
109
|
+
EOF
|
110
|
+
method = ClassRegistry['Object'].instance_method(:make_rtinfer_3)
|
111
|
+
# call make_rinfer_2 should raise for a fixnum
|
112
|
+
method.raise_type_for_types(
|
113
|
+
Types::STRING, # doesn't matter
|
114
|
+
[Types::FLOAT],
|
115
|
+
Types::NILCLASS).should equal_type(ClassRegistry['TypeError'].as_type)
|
116
|
+
method.raise_type_for_types(
|
117
|
+
Types::STRING, # doesn't matter
|
118
|
+
[ClassRegistry['Bignum'].as_type],
|
119
|
+
Types::NILCLASS).should equal_type(ClassRegistry['ArgumentError'].as_type)
|
120
|
+
method.raise_type_for_types(
|
121
|
+
Types::STRING, # doesn't matter
|
122
|
+
[Types::ARRAY],
|
123
|
+
Types::NILCLASS).should equal_type(ClassRegistry['NoMethodError'].as_type)
|
124
|
+
method.raise_type_for_types(
|
125
|
+
Types::STRING, # doesn't matter
|
126
|
+
[Types::STRING],
|
127
|
+
Types::NILCLASS).should equal_type(Types::EMPTY)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'can infer raises from calls to the annotated String class' do
|
131
|
+
g = cfg <<-EOF
|
132
|
+
class RTInfer4
|
133
|
+
def silly(x)
|
134
|
+
x.getbyte(x.size * 2)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
EOF
|
138
|
+
method = ClassRegistry['RTInfer4'].instance_method(:silly)
|
139
|
+
method.raise_type_for_types(
|
140
|
+
Utilities.type_for(ClassRegistry['RTInfer4']),
|
141
|
+
[Types::STRING],
|
142
|
+
Types::NILCLASS).should equal_type(ClassRegistry['IndexError'].as_type |
|
143
|
+
ClassRegistry['TypeError'].as_type)
|
144
|
+
method.raise_type_for_types(
|
145
|
+
Utilities.type_for(ClassRegistry['RTInfer4']),
|
146
|
+
[Types::FIXNUM],
|
147
|
+
Types::NILCLASS).should equal_type(ClassRegistry['NoMethodError'].as_type)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'can infer a guaranteed NoMethodError from privacy violations' do
|
151
|
+
g = cfg <<-EOF
|
152
|
+
class RTInfer5
|
153
|
+
def foo
|
154
|
+
end
|
155
|
+
private :foo
|
156
|
+
|
157
|
+
def bar
|
158
|
+
self.foo # error!
|
159
|
+
end
|
160
|
+
end
|
161
|
+
EOF
|
162
|
+
method = ClassRegistry['RTInfer5'].instance_method(:bar)
|
163
|
+
method.raise_type_for_types(
|
164
|
+
Utilities.type_for(ClassRegistry['RTInfer5'])).should(
|
165
|
+
equal_type(ClassRegistry['NoMethodError'].as_type))
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'can infer a potential lookup failure when a successful one exists' do
|
169
|
+
g = cfg <<-EOF
|
170
|
+
class RTInfer6
|
171
|
+
def bar
|
172
|
+
if gets.size > 0
|
173
|
+
x = 'hello'
|
174
|
+
else
|
175
|
+
x = 5
|
176
|
+
end
|
177
|
+
x.intern # error sometimes
|
178
|
+
end
|
179
|
+
end
|
180
|
+
EOF
|
181
|
+
method = ClassRegistry['RTInfer6'].instance_method(:bar)
|
182
|
+
method.raise_type_for_types(
|
183
|
+
Utilities.type_for(ClassRegistry['RTInfer6'])).should(
|
184
|
+
equal_type(ClassRegistry['NoMethodError'].as_type))
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'can infer an ArgumentError when invalid arities are given' do
|
188
|
+
g = cfg <<-EOF
|
189
|
+
class RTInfer7
|
190
|
+
def foo(*args)
|
191
|
+
bar(*args)
|
192
|
+
end
|
193
|
+
def bar(a, b=1, c=2, d)
|
194
|
+
a
|
195
|
+
end
|
196
|
+
end
|
197
|
+
EOF
|
198
|
+
method = ClassRegistry['RTInfer7'].instance_method(:foo)
|
199
|
+
method.raise_type_for_types(
|
200
|
+
ClassRegistry['RTInfer7'].as_type).should(
|
201
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
202
|
+
method.raise_type_for_types(
|
203
|
+
ClassRegistry['RTInfer7'].as_type,
|
204
|
+
[Types::STRING]).should(
|
205
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
206
|
+
method.raise_type_for_types(
|
207
|
+
ClassRegistry['RTInfer7'].as_type,
|
208
|
+
[Types::STRING, Types::FIXNUM]).should(
|
209
|
+
equal_type(Types::EMPTY))
|
210
|
+
method.raise_type_for_types(
|
211
|
+
ClassRegistry['RTInfer7'].as_type,
|
212
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM]).should(
|
213
|
+
equal_type(Types::EMPTY))
|
214
|
+
method.raise_type_for_types(
|
215
|
+
ClassRegistry['RTInfer7'].as_type,
|
216
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM, Types::ARRAY]).should(
|
217
|
+
equal_type(Types::EMPTY))
|
218
|
+
method.raise_type_for_types(
|
219
|
+
ClassRegistry['RTInfer7'].as_type,
|
220
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM, Types::ARRAY, Types::HASH]).should(
|
221
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'can infer an ArgumentError when super provides incorrect arities' do
|
225
|
+
g = cfg <<-EOF
|
226
|
+
class RTInfer8
|
227
|
+
def foo(a, b=1, c=2, d)
|
228
|
+
a
|
229
|
+
end
|
230
|
+
end
|
231
|
+
class RTInfer8B < RTInfer8
|
232
|
+
def foo(*args)
|
233
|
+
super(*args)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
EOF
|
237
|
+
method = ClassRegistry['RTInfer8B'].instance_method(:foo)
|
238
|
+
method.raise_type_for_types(
|
239
|
+
ClassRegistry['RTInfer8B'].as_type).should(
|
240
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
241
|
+
method.raise_type_for_types(
|
242
|
+
ClassRegistry['RTInfer8B'].as_type,
|
243
|
+
[Types::STRING]).should(
|
244
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
245
|
+
method.raise_type_for_types(
|
246
|
+
ClassRegistry['RTInfer8B'].as_type,
|
247
|
+
[Types::STRING, Types::FIXNUM]).should(
|
248
|
+
equal_type(Types::EMPTY))
|
249
|
+
method.raise_type_for_types(
|
250
|
+
ClassRegistry['RTInfer8B'].as_type,
|
251
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM]).should(
|
252
|
+
equal_type(Types::EMPTY))
|
253
|
+
method.raise_type_for_types(
|
254
|
+
ClassRegistry['RTInfer8B'].as_type,
|
255
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM, Types::ARRAY]).should(
|
256
|
+
equal_type(Types::EMPTY))
|
257
|
+
method.raise_type_for_types(
|
258
|
+
ClassRegistry['RTInfer8B'].as_type,
|
259
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM, Types::ARRAY, Types::HASH]).should(
|
260
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'can infer an ArgumentError when zsuper provides incorrect arities' do
|
264
|
+
g = cfg <<-EOF
|
265
|
+
class RTInfer9
|
266
|
+
def foo(a, b=1, c=2, d)
|
267
|
+
a
|
268
|
+
end
|
269
|
+
end
|
270
|
+
class RTInfer9B < RTInfer9
|
271
|
+
def foo(*args)
|
272
|
+
super
|
273
|
+
end
|
274
|
+
end
|
275
|
+
EOF
|
276
|
+
method = ClassRegistry['RTInfer9B'].instance_method(:foo)
|
277
|
+
method.raise_type_for_types(
|
278
|
+
ClassRegistry['RTInfer9B'].as_type).should(
|
279
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
280
|
+
method.raise_type_for_types(
|
281
|
+
ClassRegistry['RTInfer9B'].as_type,
|
282
|
+
[Types::STRING]).should(
|
283
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
284
|
+
method.raise_type_for_types(
|
285
|
+
ClassRegistry['RTInfer9B'].as_type,
|
286
|
+
[Types::STRING, Types::FIXNUM]).should(
|
287
|
+
equal_type(Types::EMPTY))
|
288
|
+
method.raise_type_for_types(
|
289
|
+
ClassRegistry['RTInfer9B'].as_type,
|
290
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM]).should(
|
291
|
+
equal_type(Types::EMPTY))
|
292
|
+
method.raise_type_for_types(
|
293
|
+
ClassRegistry['RTInfer9B'].as_type,
|
294
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM, Types::ARRAY]).should(
|
295
|
+
equal_type(Types::EMPTY))
|
296
|
+
method.raise_type_for_types(
|
297
|
+
ClassRegistry['RTInfer9B'].as_type,
|
298
|
+
[Types::STRING, Types::FIXNUM, Types::BIGNUM, Types::ARRAY, Types::HASH]).should(
|
299
|
+
equal_type(ClassRegistry['ArgumentError'].as_type))
|
300
|
+
end
|
301
|
+
end
|