rdl 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/CHANGES.md +35 -0
- data/README.md +153 -116
- data/bin/rdl_query +1 -1
- data/extras/type_tests/typetests.rb +905 -0
- data/lib/rdl.rb +0 -1
- data/lib/rdl/boot.rb +108 -77
- data/lib/rdl/boot_rails.rb +2 -8
- data/lib/rdl/config.rb +44 -17
- data/lib/rdl/contracts/flat.rb +1 -1
- data/lib/rdl/info.rb +3 -3
- data/lib/rdl/query.rb +11 -11
- data/lib/rdl/typecheck.rb +399 -136
- data/lib/rdl/types/finite_hash.rb +3 -2
- data/lib/rdl/types/generic.rb +7 -6
- data/lib/rdl/types/intersection.rb +3 -2
- data/lib/rdl/types/lexer.rex +2 -3
- data/lib/rdl/types/lexer.rex.rb +1 -4
- data/lib/rdl/types/method.rb +7 -6
- data/lib/rdl/types/nominal.rb +10 -1
- data/lib/rdl/types/parser.racc +7 -8
- data/lib/rdl/types/parser.tab.rb +108 -109
- data/lib/rdl/types/structural.rb +1 -0
- data/lib/rdl/types/tuple.rb +2 -2
- data/lib/rdl/types/type.rb +8 -8
- data/lib/rdl/types/type_inferencer.rb +1 -1
- data/lib/rdl/types/union.rb +2 -1
- data/lib/rdl/util.rb +28 -3
- data/lib/rdl/wrap.rb +216 -165
- data/lib/rdl_disable.rb +22 -15
- data/lib/types/core.rb +2 -4
- data/lib/types/core/_aliases.rb +14 -0
- data/lib/types/core/abbrev.rb +3 -0
- data/lib/types/core/array.rb +139 -0
- data/lib/types/core/base64.rb +8 -0
- data/lib/types/core/basic_object.rb +12 -0
- data/lib/types/core/benchmark.rb +9 -0
- data/lib/types/core/bigdecimal.rb +223 -0
- data/lib/types/core/bigmath.rb +10 -0
- data/lib/types/core/bignum.rb +214 -0
- data/lib/types/core/class.rb +15 -0
- data/lib/types/core/complex.rb +123 -0
- data/lib/types/core/coverage.rb +4 -0
- data/lib/types/core/csv.rb +3 -0
- data/lib/types/core/date.rb +4 -0
- data/lib/types/core/dir.rb +37 -0
- data/lib/types/core/encoding.rb +21 -0
- data/lib/types/core/enumerable.rb +96 -0
- data/lib/types/core/enumerator.rb +24 -0
- data/lib/types/core/exception.rb +15 -0
- data/lib/types/core/file.rb +125 -0
- data/lib/types/core/fileutils.rb +4 -0
- data/lib/types/core/fixnum.rb +213 -0
- data/lib/types/core/float.rb +199 -0
- data/lib/types/core/gem.rb +19 -0
- data/lib/types/core/hash.rb +72 -0
- data/lib/types/core/integer.rb +194 -0
- data/lib/types/core/io.rb +101 -0
- data/lib/types/core/kernel.rb +89 -0
- data/lib/types/core/marshal.rb +3 -0
- data/lib/types/core/matchdata.rb +24 -0
- data/lib/types/core/math.rb +50 -0
- data/lib/types/core/module.rb +81 -0
- data/lib/types/core/nil.rb +11 -0
- data/lib/types/core/numeric.rb +56 -0
- data/lib/types/core/object.rb +73 -0
- data/lib/types/core/pathname.rb +104 -0
- data/lib/types/core/proc.rb +12 -0
- data/lib/types/core/process.rb +110 -0
- data/lib/types/core/random.rb +13 -0
- data/lib/types/core/range.rb +37 -0
- data/lib/types/core/rational.rb +207 -0
- data/lib/types/core/regexp.rb +28 -0
- data/lib/types/core/set.rb +56 -0
- data/lib/types/core/string.rb +140 -0
- data/lib/types/core/strscan.rb +6 -0
- data/lib/types/core/symbol.rb +27 -0
- data/lib/types/core/time.rb +66 -0
- data/lib/types/core/uri.rb +18 -0
- data/lib/types/core/yaml.rb +3 -0
- data/lib/types/devise.rb +1 -0
- data/lib/types/devise/controller_helpers.rb +3 -0
- data/lib/types/devise/parameter_sanitizer.rb +2 -0
- data/lib/types/pundit.rb +2 -0
- data/lib/types/rails/_helpers.rb +50 -0
- data/lib/types/rails/abstract_controller/translation.rb +2 -0
- data/lib/types/rails/action_controller/base.rb +3 -0
- data/lib/types/rails/action_controller/instrumentation.rb +6 -0
- data/lib/types/rails/action_controller/metal.rb +3 -0
- data/lib/types/rails/action_controller/mime_responds.rb +13 -0
- data/lib/types/rails/action_controller/parameters.rb +3 -0
- data/lib/types/{rails-5.x → rails}/action_controller/strong_parameters.rb +4 -8
- data/lib/types/rails/action_dispatch/flashhash.rb +8 -0
- data/lib/types/rails/action_dispatch/routing.rb +10 -0
- data/lib/types/rails/action_mailer/base.rb +2 -0
- data/lib/types/rails/action_mailer/message_delivery.rb +2 -0
- data/lib/types/rails/action_view/helpers_sanitizehelper.rb +2 -0
- data/lib/types/rails/action_view/helpers_urlhelper.rb +5 -0
- data/lib/types/rails/active_model/errors.rb +14 -0
- data/lib/types/rails/active_model/validations.rb +2 -0
- data/lib/types/rails/active_record/associations.rb +208 -0
- data/lib/types/rails/active_record/base.rb +2 -0
- data/lib/types/rails/active_record/core.rb +2 -0
- data/lib/types/rails/active_record/finder_methods.rb +2 -0
- data/lib/types/rails/active_record/model_schema.rb +37 -0
- data/lib/types/rails/active_record/relation.rb +11 -0
- data/lib/types/rails/active_record/schema_types.rb +51 -0
- data/lib/types/rails/active_record/validations.rb +2 -0
- data/lib/types/rails/active_support/base.rb +2 -0
- data/lib/types/rails/active_support/logger.rb +3 -0
- data/lib/types/rails/active_support/tagged_logging.rb +2 -0
- data/lib/types/rails/active_support/time_with_zone.rb +13 -0
- data/lib/types/rails/active_support/time_zone.rb +2 -0
- data/lib/types/rails/fixnum.rb +2 -0
- data/lib/types/rails/integer.rb +2 -0
- data/lib/types/rails/rack/request.rb +2 -0
- data/lib/types/rails/string.rb +3 -0
- data/lib/types/rails/time.rb +1 -0
- data/rdl.gemspec +2 -2
- data/test/disabled_test_rdoc.rb +8 -8
- data/test/test_alias.rb +1 -0
- data/test/test_dsl.rb +4 -4
- data/test/test_generic.rb +45 -38
- data/test/test_intersection.rb +10 -10
- data/test/test_le.rb +103 -102
- data/test/test_member.rb +33 -33
- data/test/test_parser.rb +101 -96
- data/test/test_query.rb +84 -84
- data/test/test_rdl.rb +87 -52
- data/test/test_rdl_type.rb +26 -9
- data/test/test_type_contract.rb +32 -31
- data/test/test_typecheck.rb +802 -436
- data/test/test_types.rb +39 -39
- data/test/test_wrap.rb +3 -2
- metadata +91 -120
- data/extras/type_tests/%.rb +0 -171
- data/extras/type_tests/&.rb +0 -159
- data/extras/type_tests/**.rb +0 -222
- data/extras/type_tests/*.rb +0 -177
- data/extras/type_tests/+.rb +0 -170
- data/extras/type_tests/-.rb +0 -171
- data/extras/type_tests/1scomp.rb +0 -157
- data/extras/type_tests/<.rb +0 -170
- data/extras/type_tests/<<.rb +0 -159
- data/extras/type_tests/>>.rb +0 -159
- data/extras/type_tests/[].rb +0 -163
- data/extras/type_tests/^.rb +0 -159
- data/extras/type_tests/abs.rb +0 -155
- data/extras/type_tests/abs2.rb +0 -164
- data/extras/type_tests/angle.rb +0 -157
- data/extras/type_tests/arg.rb +0 -157
- data/extras/type_tests/bit_length.rb +0 -157
- data/extras/type_tests/ceil.rb +0 -157
- data/extras/type_tests/ceilRational.rb +0 -160
- data/extras/type_tests/conj.rb +0 -158
- data/extras/type_tests/defwhere.rb +0 -86
- data/extras/type_tests/denominator.rb +0 -157
- data/extras/type_tests/div.rb +0 -172
- data/extras/type_tests/divslash.rb +0 -179
- data/extras/type_tests/even?.rb +0 -157
- data/extras/type_tests/fdiv.rb +0 -244
- data/extras/type_tests/finite?.rb +0 -157
- data/extras/type_tests/floor.rb +0 -157
- data/extras/type_tests/floorRational.rb +0 -161
- data/extras/type_tests/hash.rb +0 -157
- data/extras/type_tests/imag.rb +0 -158
- data/extras/type_tests/infinite?.rb +0 -157
- data/extras/type_tests/modulo.rb +0 -171
- data/extras/type_tests/nan?.rb +0 -157
- data/extras/type_tests/neg.rb +0 -155
- data/extras/type_tests/next.rb +0 -157
- data/extras/type_tests/next_float.rb +0 -157
- data/extras/type_tests/numerator.rb +0 -157
- data/extras/type_tests/phase.rb +0 -157
- data/extras/type_tests/prev_float.rb +0 -157
- data/extras/type_tests/quo.rb +0 -179
- data/extras/type_tests/rationalize.rb +0 -157
- data/extras/type_tests/rationalizeArg.rb +0 -198
- data/extras/type_tests/real.rb +0 -157
- data/extras/type_tests/real?.rb +0 -157
- data/extras/type_tests/round.rb +0 -157
- data/extras/type_tests/roundArg.rb +0 -169
- data/extras/type_tests/size.rb +0 -157
- data/extras/type_tests/to_c.rb +0 -157
- data/extras/type_tests/to_f.rb +0 -155
- data/extras/type_tests/to_i.rb +0 -157
- data/extras/type_tests/to_r.rb +0 -157
- data/extras/type_tests/to_s.rb +0 -157
- data/extras/type_tests/truncate.rb +0 -157
- data/extras/type_tests/truncateArg.rb +0 -166
- data/extras/type_tests/type tests +0 -1
- data/extras/type_tests/zero?.rb +0 -155
- data/extras/type_tests/|.rb +0 -159
- data/lib/types/core-ruby-2.x/_aliases.rb +0 -15
- data/lib/types/core-ruby-2.x/abbrev.rb +0 -5
- data/lib/types/core-ruby-2.x/array.rb +0 -137
- data/lib/types/core-ruby-2.x/base64.rb +0 -10
- data/lib/types/core-ruby-2.x/basic_object.rb +0 -14
- data/lib/types/core-ruby-2.x/benchmark.rb +0 -11
- data/lib/types/core-ruby-2.x/bigdecimal.rb +0 -224
- data/lib/types/core-ruby-2.x/bigmath.rb +0 -12
- data/lib/types/core-ruby-2.x/bignum.rb +0 -214
- data/lib/types/core-ruby-2.x/class.rb +0 -17
- data/lib/types/core-ruby-2.x/complex.rb +0 -124
- data/lib/types/core-ruby-2.x/coverage.rb +0 -6
- data/lib/types/core-ruby-2.x/csv.rb +0 -5
- data/lib/types/core-ruby-2.x/date.rb +0 -6
- data/lib/types/core-ruby-2.x/dir.rb +0 -38
- data/lib/types/core-ruby-2.x/encoding.rb +0 -23
- data/lib/types/core-ruby-2.x/enumerable.rb +0 -98
- data/lib/types/core-ruby-2.x/enumerator.rb +0 -26
- data/lib/types/core-ruby-2.x/exception.rb +0 -17
- data/lib/types/core-ruby-2.x/file.rb +0 -126
- data/lib/types/core-ruby-2.x/fileutils.rb +0 -6
- data/lib/types/core-ruby-2.x/fixnum.rb +0 -213
- data/lib/types/core-ruby-2.x/float.rb +0 -199
- data/lib/types/core-ruby-2.x/gem.rb +0 -247
- data/lib/types/core-ruby-2.x/hash.rb +0 -72
- data/lib/types/core-ruby-2.x/integer.rb +0 -197
- data/lib/types/core-ruby-2.x/io.rb +0 -103
- data/lib/types/core-ruby-2.x/kernel.rb +0 -90
- data/lib/types/core-ruby-2.x/marshal.rb +0 -5
- data/lib/types/core-ruby-2.x/matchdata.rb +0 -26
- data/lib/types/core-ruby-2.x/math.rb +0 -53
- data/lib/types/core-ruby-2.x/module.rb +0 -83
- data/lib/types/core-ruby-2.x/nil.rb +0 -12
- data/lib/types/core-ruby-2.x/numeric.rb +0 -56
- data/lib/types/core-ruby-2.x/object.rb +0 -75
- data/lib/types/core-ruby-2.x/pathname.rb +0 -106
- data/lib/types/core-ruby-2.x/proc.rb +0 -16
- data/lib/types/core-ruby-2.x/process.rb +0 -127
- data/lib/types/core-ruby-2.x/random.rb +0 -17
- data/lib/types/core-ruby-2.x/range.rb +0 -39
- data/lib/types/core-ruby-2.x/rational.rb +0 -209
- data/lib/types/core-ruby-2.x/regexp.rb +0 -30
- data/lib/types/core-ruby-2.x/set.rb +0 -58
- data/lib/types/core-ruby-2.x/string.rb +0 -143
- data/lib/types/core-ruby-2.x/strscan.rb +0 -7
- data/lib/types/core-ruby-2.x/symbol.rb +0 -29
- data/lib/types/core-ruby-2.x/time.rb +0 -68
- data/lib/types/core-ruby-2.x/uri.rb +0 -20
- data/lib/types/core-ruby-2.x/yaml.rb +0 -5
- data/lib/types/rails-5.x/_helpers.rb +0 -52
- data/lib/types/rails-5.x/action_controller/mime_responds.rb +0 -11
- data/lib/types/rails-5.x/action_dispatch/routing.rb +0 -10
- data/lib/types/rails-5.x/active_model/errors.rb +0 -15
- data/lib/types/rails-5.x/active_model/validations.rb +0 -5
- data/lib/types/rails-5.x/active_record/associations.rb +0 -190
- data/lib/types/rails-5.x/active_record/core.rb +0 -3
- data/lib/types/rails-5.x/active_record/model_schema.rb +0 -39
- data/lib/types/rails-5.x/fixnum.rb +0 -3
data/test/test_le.rb
CHANGED
|
@@ -17,7 +17,7 @@ class TestLe < Minitest::Test
|
|
|
17
17
|
|
|
18
18
|
# convert arg string to a type
|
|
19
19
|
def tt(t)
|
|
20
|
-
|
|
20
|
+
RDL::Globals.parser.scan_str('#T ' + t)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def setup
|
|
@@ -29,49 +29,49 @@ class TestLe < Minitest::Test
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def test_nil
|
|
32
|
-
assert (
|
|
33
|
-
assert (
|
|
34
|
-
assert (
|
|
35
|
-
assert (
|
|
36
|
-
assert (not (
|
|
37
|
-
assert (not (
|
|
38
|
-
assert (not (
|
|
39
|
-
assert (not (
|
|
40
|
-
assert (not (@tbasicobject <=
|
|
41
|
-
assert (not (@tsymfoo <=
|
|
32
|
+
assert (RDL::Globals.types[:nil] <= RDL::Globals.types[:top])
|
|
33
|
+
assert (RDL::Globals.types[:nil] <= RDL::Globals.types[:string])
|
|
34
|
+
assert (RDL::Globals.types[:nil] <= RDL::Globals.types[:object])
|
|
35
|
+
assert (RDL::Globals.types[:nil] <= @tbasicobject)
|
|
36
|
+
assert (not (RDL::Globals.types[:nil] <= @tsymfoo)) # nil no longer <= other singleton types
|
|
37
|
+
assert (not (RDL::Globals.types[:top] <= RDL::Globals.types[:nil]))
|
|
38
|
+
assert (not (RDL::Globals.types[:string] <= RDL::Globals.types[:nil]))
|
|
39
|
+
assert (not (RDL::Globals.types[:object] <= RDL::Globals.types[:nil]))
|
|
40
|
+
assert (not (@tbasicobject <= RDL::Globals.types[:nil]))
|
|
41
|
+
assert (not (@tsymfoo <= RDL::Globals.types[:nil]))
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def test_top
|
|
45
|
-
assert (not (
|
|
46
|
-
assert (not (
|
|
47
|
-
assert (not (
|
|
48
|
-
assert (not (
|
|
49
|
-
assert (not (
|
|
50
|
-
assert (
|
|
51
|
-
assert (
|
|
52
|
-
assert (
|
|
53
|
-
assert (@tbasicobject <=
|
|
54
|
-
assert (@tsymfoo <=
|
|
45
|
+
assert (not (RDL::Globals.types[:top] <= RDL::Globals.types[:nil]))
|
|
46
|
+
assert (not (RDL::Globals.types[:top] <= RDL::Globals.types[:string]))
|
|
47
|
+
assert (not (RDL::Globals.types[:top] <= RDL::Globals.types[:object]))
|
|
48
|
+
assert (not (RDL::Globals.types[:top] <= @tbasicobject))
|
|
49
|
+
assert (not (RDL::Globals.types[:top] <= @tsymfoo))
|
|
50
|
+
assert (RDL::Globals.types[:top] <= RDL::Globals.types[:top])
|
|
51
|
+
assert (RDL::Globals.types[:string] <= RDL::Globals.types[:top])
|
|
52
|
+
assert (RDL::Globals.types[:object] <= RDL::Globals.types[:top])
|
|
53
|
+
assert (@tbasicobject <= RDL::Globals.types[:top])
|
|
54
|
+
assert (@tsymfoo <= RDL::Globals.types[:top])
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def test_sym
|
|
58
|
-
assert (
|
|
58
|
+
assert (RDL::Globals.types[:symbol] <= RDL::Globals.types[:symbol])
|
|
59
59
|
assert (@tsymfoo <= @tsymfoo)
|
|
60
|
-
assert (@tsymfoo <=
|
|
61
|
-
assert (not (
|
|
60
|
+
assert (@tsymfoo <= RDL::Globals.types[:symbol])
|
|
61
|
+
assert (not (RDL::Globals.types[:symbol] <= @tsymfoo))
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def test_nominal
|
|
65
|
-
assert (
|
|
66
|
-
assert (
|
|
67
|
-
assert (not (
|
|
68
|
-
assert (not (
|
|
69
|
-
assert (
|
|
70
|
-
assert (
|
|
71
|
-
assert (
|
|
72
|
-
assert (not (
|
|
73
|
-
assert (not (@tbasicobject <=
|
|
74
|
-
assert (not (@tbasicobject <=
|
|
65
|
+
assert (RDL::Globals.types[:string] <= RDL::Globals.types[:string])
|
|
66
|
+
assert (RDL::Globals.types[:symbol] <= RDL::Globals.types[:symbol])
|
|
67
|
+
assert (not (RDL::Globals.types[:string] <= RDL::Globals.types[:symbol]))
|
|
68
|
+
assert (not (RDL::Globals.types[:symbol] <= RDL::Globals.types[:string]))
|
|
69
|
+
assert (RDL::Globals.types[:string] <= RDL::Globals.types[:object])
|
|
70
|
+
assert (RDL::Globals.types[:string] <= @tbasicobject)
|
|
71
|
+
assert (RDL::Globals.types[:object] <= @tbasicobject)
|
|
72
|
+
assert (not (RDL::Globals.types[:object] <= RDL::Globals.types[:string]))
|
|
73
|
+
assert (not (@tbasicobject <= RDL::Globals.types[:string]))
|
|
74
|
+
assert (not (@tbasicobject <= RDL::Globals.types[:object]))
|
|
75
75
|
assert (@ta <= @ta)
|
|
76
76
|
assert (@tb <= @ta)
|
|
77
77
|
assert (@tc <= @ta)
|
|
@@ -84,55 +84,55 @@ class TestLe < Minitest::Test
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def test_union
|
|
87
|
-
tstring_or_sym = UnionType.new(
|
|
88
|
-
assert (tstring_or_sym <=
|
|
89
|
-
assert (not (
|
|
87
|
+
tstring_or_sym = UnionType.new(RDL::Globals.types[:string], RDL::Globals.types[:symbol])
|
|
88
|
+
assert (tstring_or_sym <= RDL::Globals.types[:object])
|
|
89
|
+
assert (not (RDL::Globals.types[:object] <= tstring_or_sym))
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def test_tuple
|
|
93
|
-
t1 = TupleType.new(
|
|
94
|
-
t2 = TupleType.new(
|
|
93
|
+
t1 = TupleType.new(RDL::Globals.types[:symbol], RDL::Globals.types[:string])
|
|
94
|
+
t2 = TupleType.new(RDL::Globals.types[:object], RDL::Globals.types[:object])
|
|
95
95
|
tarray = NominalType.new("Array")
|
|
96
96
|
assert (t1 <= t1)
|
|
97
97
|
assert (t2 <= t2)
|
|
98
98
|
assert (not (t2 <= t1))
|
|
99
99
|
assert (not (tarray <= t1))
|
|
100
100
|
assert (t1 <= t2) # covariant subtyping since tuples are *immutable*
|
|
101
|
-
assert (tt("[1, 2, 3]") <= tt("[
|
|
102
|
-
assert (tt("[
|
|
101
|
+
assert (tt("[1, 2, 3]") <= tt("[Integer, Integer, Integer]")) # covariant subtyping with singletons
|
|
102
|
+
assert (tt("[Integer, Integer, Integer]") <= tt("[Object, Object, Object]"))
|
|
103
103
|
assert (tt("[1, 2, 3]") <= tt("[Object, Object, Object]"))
|
|
104
104
|
|
|
105
105
|
# subtyping of tuples and arrays
|
|
106
|
-
tfs_1 = tt "[
|
|
107
|
-
tafs_1 = tt "Array<
|
|
106
|
+
tfs_1 = tt "[Integer, String]"
|
|
107
|
+
tafs_1 = tt "Array<Integer or String>"
|
|
108
108
|
assert (tfs_1 <= tafs_1) # subtyping allowed by tfs_1 promoted to array
|
|
109
|
-
tfs2_1 = tt "[
|
|
109
|
+
tfs2_1 = tt "[Integer, String]"
|
|
110
110
|
assert (not (tfs_1 <= tfs2_1)) # t12 has been promoted to array, no longer subtype
|
|
111
111
|
|
|
112
|
-
tfs_2 = tt "[
|
|
113
|
-
tfs2_2 = tt "[
|
|
112
|
+
tfs_2 = tt "[Integer, String]"
|
|
113
|
+
tfs2_2 = tt "[Integer, String]"
|
|
114
114
|
assert (tfs_2 <= tfs2_2) # this is allowed here because tfs_2 is still a tuple
|
|
115
|
-
tafs_2 = tt "Array<
|
|
115
|
+
tafs_2 = tt "Array<Integer or String>"
|
|
116
116
|
assert (not (tfs_2 <= tafs_2)) # subtyping not allowed because tfs_2 <= tfs2_2 unsatisfiable after tfs_2 promoted
|
|
117
117
|
|
|
118
|
-
tfs_3 = tt "[
|
|
118
|
+
tfs_3 = tt "[Integer, String]"
|
|
119
119
|
tfs2_3 = tt "[Object, Object]"
|
|
120
120
|
assert (tfs_3 <= tfs2_3) # this is allowed here because t12a is still a tuple
|
|
121
121
|
tafs_3 = tt "Array<Object>"
|
|
122
122
|
assert (not (tfs2_3 <= tafs_3)) # subtyping not allowed because tfs_3 <= tfs2_3 unsatisfiable after tfs2_3 promoted
|
|
123
123
|
|
|
124
|
-
tfs_4 = tt "[
|
|
125
|
-
tfs2_4 = tt "[
|
|
124
|
+
tfs_4 = tt "[Integer, String]"
|
|
125
|
+
tfs2_4 = tt "[Integer, String]"
|
|
126
126
|
assert (tfs_4 <= tfs2_4) # allowed, types are the same
|
|
127
|
-
tafs_4 = tt "Array<
|
|
127
|
+
tafs_4 = tt "Array<Integer or String>"
|
|
128
128
|
assert (tfs2_4 <= tafs_4) # allowed, both tfs2_4 and tfs_4 promoted to array
|
|
129
|
-
tfs3_4 = tt "[
|
|
129
|
+
tfs3_4 = tt "[Integer, String]"
|
|
130
130
|
assert (not(tfs_4 <= tfs3_4)) # not allowed, tfs_4 has been promoted
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def test_finite_hash
|
|
134
134
|
t12 = tt "{a: 1, b: 2}"
|
|
135
|
-
tfs = tt "{a:
|
|
135
|
+
tfs = tt "{a: Integer, b: Integer}"
|
|
136
136
|
too = tt "{a: Object, b: Object}"
|
|
137
137
|
assert (t12 <= tfs)
|
|
138
138
|
assert (t12 <= too)
|
|
@@ -143,36 +143,36 @@ class TestLe < Minitest::Test
|
|
|
143
143
|
|
|
144
144
|
# subtyping of finite hashes and hashes; same pattern as tuples
|
|
145
145
|
# subtyping of tuples and arrays
|
|
146
|
-
tfs_1 = tt "{x:
|
|
147
|
-
thfs_1 = tt "Hash<Symbol,
|
|
146
|
+
tfs_1 = tt "{x: Integer, y: String}"
|
|
147
|
+
thfs_1 = tt "Hash<Symbol, Integer or String>"
|
|
148
148
|
assert (tfs_1 <= thfs_1) # subtyping allowed because tfs_1 promoted to hash
|
|
149
|
-
tfs2_1 = tt "{x:
|
|
149
|
+
tfs2_1 = tt "{x: Integer, y: String}"
|
|
150
150
|
assert (not (tfs_1 <= tfs2_1)) # t12 has been promoted to hash, no longer subtype
|
|
151
151
|
|
|
152
|
-
tfs_2 = tt "{x:
|
|
153
|
-
tfs2_2 = tt "{x:
|
|
152
|
+
tfs_2 = tt "{x: Integer, y: String}"
|
|
153
|
+
tfs2_2 = tt "{x: Integer, y: String}"
|
|
154
154
|
assert (tfs_2 <= tfs2_2) # this is allowed here because tfs_2 is still finite
|
|
155
|
-
thfs_2 = tt "Hash<Symbol,
|
|
155
|
+
thfs_2 = tt "Hash<Symbol, Integer or String>"
|
|
156
156
|
assert (not (tfs_2 <= thfs_2)) # subtyping not allowed because tfs_2 <= tfs2_2 unsatisfiable after tfs_2 promoted
|
|
157
157
|
|
|
158
|
-
tfs_3 = tt "{x:
|
|
158
|
+
tfs_3 = tt "{x: Integer, y: String}"
|
|
159
159
|
tfs2_3 = tt "{x: Object, y: Object}"
|
|
160
160
|
assert (tfs_3 <= tfs2_3) # this is allowed here because t12a is still finite
|
|
161
161
|
thfs_3 = tt "Hash<Symbol, Object>"
|
|
162
162
|
assert (not (tfs2_3 <= thfs_3)) # subtyping not allowed because tfs_3 <= tfs2_3 unsatisfiable after tfs2_3 promoted
|
|
163
163
|
|
|
164
|
-
tfs_4 = tt "{x:
|
|
165
|
-
tfs2_4 = tt "{x:
|
|
164
|
+
tfs_4 = tt "{x: Integer, y: String}"
|
|
165
|
+
tfs2_4 = tt "{x: Integer, y: String}"
|
|
166
166
|
assert (tfs_4 <= tfs2_4) # allowed, types are the same
|
|
167
|
-
thfs_4 = tt "Hash<Symbol,
|
|
167
|
+
thfs_4 = tt "Hash<Symbol, Integer or String>"
|
|
168
168
|
assert (tfs2_4 <= thfs_4) # allowed, both tfs2_4 and tfs_4 promoted to hash
|
|
169
|
-
tfs3_4 = tt "{x:
|
|
169
|
+
tfs3_4 = tt "{x: Integer, y: String}"
|
|
170
170
|
assert (not(tfs_4 <= tfs3_4)) # not allowed, tfs_4 has been promoted
|
|
171
171
|
|
|
172
|
-
tfss_5 = tt "{x:
|
|
173
|
-
tfns_5 = tt "{x:
|
|
174
|
-
tfsn_5 = tt "{x:
|
|
175
|
-
tftn_5 = tt "{x:
|
|
172
|
+
tfss_5 = tt "{x: Integer, y: String, **Symbol}"
|
|
173
|
+
tfns_5 = tt "{x: Integer, **Symbol}"
|
|
174
|
+
tfsn_5 = tt "{x: Integer, y: String}"
|
|
175
|
+
tftn_5 = tt "{x: Integer, z: Symbol}"
|
|
176
176
|
tooo_5 = tt "{x: Object, y: Object, **Object}"
|
|
177
177
|
tono_5 = tt "{x: Object, **Object}"
|
|
178
178
|
assert (tfss_5 <= tooo_5)
|
|
@@ -190,14 +190,14 @@ class TestLe < Minitest::Test
|
|
|
190
190
|
assert (tftn_5 <= tfns_5)
|
|
191
191
|
assert (not (tftn_5 <= tfsn_5))
|
|
192
192
|
|
|
193
|
-
assert (not (tt("{x: ?
|
|
193
|
+
assert (not (tt("{x: ?Integer}") <= tt("{x: Integer}")))
|
|
194
194
|
end
|
|
195
195
|
|
|
196
196
|
def test_method
|
|
197
|
-
tss = MethodType.new([
|
|
198
|
-
tso = MethodType.new([
|
|
199
|
-
tos = MethodType.new([
|
|
200
|
-
too = MethodType.new([
|
|
197
|
+
tss = MethodType.new([RDL::Globals.types[:string]], nil, RDL::Globals.types[:string])
|
|
198
|
+
tso = MethodType.new([RDL::Globals.types[:string]], nil, RDL::Globals.types[:object])
|
|
199
|
+
tos = MethodType.new([RDL::Globals.types[:object]], nil, RDL::Globals.types[:string])
|
|
200
|
+
too = MethodType.new([RDL::Globals.types[:object]], nil, RDL::Globals.types[:object])
|
|
201
201
|
assert (tss <= tss)
|
|
202
202
|
assert (tss <= tso)
|
|
203
203
|
assert (not (tss <= tos))
|
|
@@ -214,21 +214,21 @@ class TestLe < Minitest::Test
|
|
|
214
214
|
assert (too <= tso)
|
|
215
215
|
assert (not (too <= tos))
|
|
216
216
|
assert (too <= too)
|
|
217
|
-
tbos = MethodType.new([], tos,
|
|
218
|
-
tbso = MethodType.new([], tso,
|
|
217
|
+
tbos = MethodType.new([], tos, RDL::Globals.types[:object])
|
|
218
|
+
tbso = MethodType.new([], tso, RDL::Globals.types[:object])
|
|
219
219
|
assert (tbos <= tbos)
|
|
220
220
|
assert (not (tbos <= tbso))
|
|
221
221
|
assert (tbso <= tbso)
|
|
222
222
|
assert (tbso <= tbos)
|
|
223
|
-
assert (tss <=
|
|
223
|
+
assert (tss <= RDL::Globals.types[:proc])
|
|
224
224
|
end
|
|
225
225
|
|
|
226
226
|
def test_structural
|
|
227
|
-
tso = MethodType.new([
|
|
228
|
-
tos = MethodType.new([
|
|
227
|
+
tso = MethodType.new([RDL::Globals.types[:string]], nil, RDL::Globals.types[:object])
|
|
228
|
+
tos = MethodType.new([RDL::Globals.types[:object]], nil, RDL::Globals.types[:string])
|
|
229
229
|
ts1 = StructuralType.new(m1: tso)
|
|
230
230
|
ts2 = StructuralType.new(m1: tos)
|
|
231
|
-
assert (ts1 <=
|
|
231
|
+
assert (ts1 <= RDL::Globals.types[:top])
|
|
232
232
|
assert (ts1 <= ts1)
|
|
233
233
|
assert (ts2 <= ts2)
|
|
234
234
|
assert (ts2 <= ts1)
|
|
@@ -248,6 +248,7 @@ class TestLe < Minitest::Test
|
|
|
248
248
|
end
|
|
249
249
|
|
|
250
250
|
class NomT
|
|
251
|
+
extend RDL::Annotate
|
|
251
252
|
type "() -> nil"
|
|
252
253
|
def m1()
|
|
253
254
|
nil
|
|
@@ -261,8 +262,8 @@ class TestLe < Minitest::Test
|
|
|
261
262
|
def test_nominal_structural
|
|
262
263
|
tnom = NominalType.new(Nom)
|
|
263
264
|
tnomt = NominalType.new(NomT)
|
|
264
|
-
tma = MethodType.new([], nil,
|
|
265
|
-
tmb = MethodType.new([
|
|
265
|
+
tma = MethodType.new([], nil, RDL::Globals.types[:nil])
|
|
266
|
+
tmb = MethodType.new([RDL::Globals.types[:integer]], nil, RDL::Globals.types[:nil])
|
|
266
267
|
ts1 = StructuralType.new(m1: tma)
|
|
267
268
|
assert (tnom <= ts1)
|
|
268
269
|
assert (tnomt <= ts1)
|
|
@@ -283,22 +284,22 @@ class TestLe < Minitest::Test
|
|
|
283
284
|
assert_equal false, do_leq(tt("t"), @ta, false)[0]
|
|
284
285
|
assert_equal false, do_leq(@ta, tt("t"), true)[0]
|
|
285
286
|
assert_equal [true, {t: @ta}], do_leq(@ta, tt("t"), false)
|
|
286
|
-
assert_equal [true, {}], do_leq(
|
|
287
|
-
assert_equal [true, {}], do_leq(
|
|
288
|
-
assert_equal false, do_leq(
|
|
289
|
-
assert_equal [true, {t:
|
|
287
|
+
assert_equal [true, {}], do_leq(RDL::Globals.types[:bot], tt("t"), true)
|
|
288
|
+
assert_equal [true, {}], do_leq(RDL::Globals.types[:bot], tt("t"), false)
|
|
289
|
+
assert_equal false, do_leq(RDL::Globals.types[:top], tt("t"), true)[0]
|
|
290
|
+
assert_equal [true, {t: RDL::Globals.types[:top]}], do_leq(RDL::Globals.types[:top], tt("t"), false)
|
|
290
291
|
assert_equal [true, {t: @ta, u: @ta}], do_leq(tt("t or u"), @ta, true)
|
|
291
292
|
assert_equal false, do_leq(tt("t or u"), @ta, false)[0]
|
|
292
293
|
assert_equal false, do_leq(tt("3"), tt("t"), true)[0]
|
|
293
294
|
assert_equal [true, {t: tt("3")}], do_leq(tt("3"), tt("t"), false)
|
|
294
|
-
assert_equal [true, {t:
|
|
295
|
-
assert_equal false, do_leq(tt("Array<t>"), tt("Array<
|
|
296
|
-
assert_equal [true, {t:
|
|
297
|
-
assert_equal false, do_leq(tt("Array<
|
|
298
|
-
assert_equal [true, {t:
|
|
299
|
-
assert_equal [true, {t:
|
|
300
|
-
assert_equal false, do_leq(tt("Hash<t,t>"), tt("Hash<
|
|
301
|
-
assert_equal false, do_leq(tt("[m:()->t]"), tt("[m:()->
|
|
295
|
+
assert_equal [true, {t: RDL::Globals.types[:integer]}], do_leq(tt("Array<t>"), tt("Array<Integer>"), true)
|
|
296
|
+
assert_equal false, do_leq(tt("Array<t>"), tt("Array<Integer>"), false)[0]
|
|
297
|
+
assert_equal [true, {t: RDL::Globals.types[:integer]}], do_leq(tt("Array<Integer>"), tt("Array<t>"), false)
|
|
298
|
+
assert_equal false, do_leq(tt("Array<Integer>"), tt("Array<t>"), true)[0]
|
|
299
|
+
assert_equal [true, {t: RDL::Globals.types[:integer], u: RDL::Globals.types[:string]}], do_leq(tt("Hash<t,u>"), tt("Hash<Integer,String>"), true)
|
|
300
|
+
assert_equal [true, {t: RDL::Globals.types[:integer]}], do_leq(tt("Hash<t,t>"), tt("Hash<Integer,Integer>"), true)
|
|
301
|
+
assert_equal false, do_leq(tt("Hash<t,t>"), tt("Hash<Integer,String>"), true)[0]
|
|
302
|
+
assert_equal false, do_leq(tt("[m:()->t]"), tt("[m:()->Integer]"), true)[0] # no inst inside structural types
|
|
302
303
|
end
|
|
303
304
|
|
|
304
305
|
def do_leq(tleft, tright, ileft)
|
|
@@ -309,19 +310,19 @@ class TestLe < Minitest::Test
|
|
|
309
310
|
|
|
310
311
|
# nonnull annotation is simply removed! so doesn't matter
|
|
311
312
|
def test_leq_nonnull
|
|
312
|
-
assert tt("!
|
|
313
|
-
assert tt("!
|
|
314
|
-
assert tt("
|
|
315
|
-
assert tt("!
|
|
316
|
-
assert tt("!
|
|
317
|
-
assert tt("
|
|
313
|
+
assert tt("!Integer") <= tt("!Integer")
|
|
314
|
+
assert tt("!Integer") <= tt("Integer")
|
|
315
|
+
assert tt("Integer") <= tt("!Integer")
|
|
316
|
+
assert tt("!Integer") <= tt("!Object")
|
|
317
|
+
assert tt("!Integer") <= tt("Object")
|
|
318
|
+
assert tt("Integer") <= tt("!Object")
|
|
318
319
|
end
|
|
319
320
|
|
|
320
321
|
# def test_intersection
|
|
321
322
|
# skip "<= not defined on intersection"
|
|
322
|
-
# tobject_and_basicobject = IntersectionType.new(
|
|
323
|
-
# assert (not (tobject_and_basicobject <=
|
|
324
|
-
# assert (
|
|
323
|
+
# tobject_and_basicobject = IntersectionType.new(RDL::Globals.types[:object], @tbasicobject)
|
|
324
|
+
# assert (not (tobject_and_basicobject <= RDL::Globals.types[:object]))
|
|
325
|
+
# assert (RDL::Globals.types[:object] <= tobject_and_basicobject)
|
|
325
326
|
# end
|
|
326
327
|
|
|
327
328
|
end
|
data/test/test_member.rb
CHANGED
|
@@ -17,16 +17,16 @@ class TestMember < Minitest::Test
|
|
|
17
17
|
def setup
|
|
18
18
|
@tbasicobject = NominalType.new "BasicObject"
|
|
19
19
|
@tsymfoo = SingletonType.new :foo
|
|
20
|
-
@tarraystring = GenericType.new(
|
|
21
|
-
@tarrayobject = GenericType.new(
|
|
22
|
-
@tarrayarraystring = GenericType.new(
|
|
23
|
-
@tarrayarrayobject = GenericType.new(
|
|
24
|
-
|
|
25
|
-
@thashstringstring = GenericType.new(
|
|
26
|
-
@thashobjectobject = GenericType.new(
|
|
27
|
-
@tstring_or_sym = UnionType.new(
|
|
28
|
-
@tstring_and_sym = IntersectionType.new(
|
|
29
|
-
@tobject_and_basicobject = IntersectionType.new(
|
|
20
|
+
@tarraystring = GenericType.new(RDL::Globals.types[:array], RDL::Globals.types[:string])
|
|
21
|
+
@tarrayobject = GenericType.new(RDL::Globals.types[:array], RDL::Globals.types[:object])
|
|
22
|
+
@tarrayarraystring = GenericType.new(RDL::Globals.types[:array], @tarraystring)
|
|
23
|
+
@tarrayarrayobject = GenericType.new(RDL::Globals.types[:array], @tarrayobject)
|
|
24
|
+
RDL::Globals.types[:hash] = NominalType.new Hash
|
|
25
|
+
@thashstringstring = GenericType.new(RDL::Globals.types[:hash], RDL::Globals.types[:string], RDL::Globals.types[:string])
|
|
26
|
+
@thashobjectobject = GenericType.new(RDL::Globals.types[:hash], RDL::Globals.types[:object], RDL::Globals.types[:object])
|
|
27
|
+
@tstring_or_sym = UnionType.new(RDL::Globals.types[:string], RDL::Globals.types[:symbol])
|
|
28
|
+
@tstring_and_sym = IntersectionType.new(RDL::Globals.types[:string], RDL::Globals.types[:symbol])
|
|
29
|
+
@tobject_and_basicobject = IntersectionType.new(RDL::Globals.types[:object], @tbasicobject)
|
|
30
30
|
@ta = NominalType.new A
|
|
31
31
|
@tb = NominalType.new B
|
|
32
32
|
@tc = NominalType.new C
|
|
@@ -35,26 +35,26 @@ class TestMember < Minitest::Test
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def test_nil
|
|
38
|
-
assert (
|
|
39
|
-
assert (not (
|
|
40
|
-
assert (not (
|
|
38
|
+
assert (RDL::Globals.types[:nil].member? nil)
|
|
39
|
+
assert (not (RDL::Globals.types[:nil].member? "foo"))
|
|
40
|
+
assert (not (RDL::Globals.types[:nil].member? (Object.new)))
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def test_top
|
|
44
|
-
assert (
|
|
45
|
-
assert (
|
|
46
|
-
assert (
|
|
44
|
+
assert (RDL::Globals.types[:top].member? nil)
|
|
45
|
+
assert (RDL::Globals.types[:top].member? "foo")
|
|
46
|
+
assert (RDL::Globals.types[:top].member? (Object.new))
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def test_nominal
|
|
50
50
|
o = Object.new
|
|
51
|
-
assert (
|
|
52
|
-
assert (not (
|
|
53
|
-
assert (not (
|
|
51
|
+
assert (RDL::Globals.types[:string].member? "Foo")
|
|
52
|
+
assert (not (RDL::Globals.types[:string].member? :Foo))
|
|
53
|
+
assert (not (RDL::Globals.types[:string].member? o))
|
|
54
54
|
|
|
55
|
-
assert (
|
|
56
|
-
assert (
|
|
57
|
-
assert (
|
|
55
|
+
assert (RDL::Globals.types[:object].member? "Foo")
|
|
56
|
+
assert (RDL::Globals.types[:object].member? :Foo)
|
|
57
|
+
assert (RDL::Globals.types[:object].member? o)
|
|
58
58
|
|
|
59
59
|
assert (@tkernel.member? "Foo")
|
|
60
60
|
assert (@tkernel.member? :Foo)
|
|
@@ -73,14 +73,14 @@ class TestMember < Minitest::Test
|
|
|
73
73
|
assert (not (@tc.member? b))
|
|
74
74
|
assert (@tc.member? c)
|
|
75
75
|
|
|
76
|
-
assert (
|
|
77
|
-
assert (
|
|
76
|
+
assert (RDL::Globals.types[:string].member? nil)
|
|
77
|
+
assert (RDL::Globals.types[:object].member? nil)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def test_symbol
|
|
81
|
-
assert (
|
|
82
|
-
assert (
|
|
83
|
-
assert (not (
|
|
81
|
+
assert (RDL::Globals.types[:symbol].member? :foo)
|
|
82
|
+
assert (RDL::Globals.types[:symbol].member? :bar)
|
|
83
|
+
assert (not (RDL::Globals.types[:symbol].member? "foo"))
|
|
84
84
|
assert (@tsymfoo.member? :foo)
|
|
85
85
|
assert (not (@tsymfoo.member? :bar))
|
|
86
86
|
assert (not (@tsymfoo.member? "foo"))
|
|
@@ -109,7 +109,7 @@ class TestMember < Minitest::Test
|
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
def test_tuple
|
|
112
|
-
t1 = TupleType.new(
|
|
112
|
+
t1 = TupleType.new(RDL::Globals.types[:symbol], RDL::Globals.types[:string])
|
|
113
113
|
assert (t1.member? [:foo, "foo"])
|
|
114
114
|
assert (not (t1.member? ["foo", :foo]))
|
|
115
115
|
assert (not (t1.member? [:foo, "foo", "bar"]))
|
|
@@ -119,19 +119,19 @@ class TestMember < Minitest::Test
|
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
def test_finite_hash
|
|
122
|
-
t1 = FiniteHashType.new({a:
|
|
122
|
+
t1 = FiniteHashType.new({a: RDL::Globals.types[:symbol], b: RDL::Globals.types[:string]}, nil)
|
|
123
123
|
assert (t1.member?(a: :foo, b: "foo"))
|
|
124
124
|
assert (not (t1.member?(a: 1, b: "foo")))
|
|
125
125
|
assert (not (t1.member?(a: :foo)))
|
|
126
126
|
assert (not (t1.member?(b: "foo")))
|
|
127
127
|
assert (not (t1.member?(a: :foo, b: "foo", c: :baz)))
|
|
128
|
-
t2 = FiniteHashType.new({"a"
|
|
128
|
+
t2 = FiniteHashType.new({"a"=>RDL::Globals.types[:symbol], 2=>RDL::Globals.types[:string]}, nil)
|
|
129
129
|
assert (t2.member?({"a"=>:foo, 2=>"foo"}))
|
|
130
130
|
assert (not (t2.member?({"a"=>2, 2=>"foo"})))
|
|
131
131
|
assert (not (t2.member?({"a"=>:foo})))
|
|
132
132
|
assert (not (t2.member?({2=>"foo"})))
|
|
133
133
|
assert (not (t2.member?({"a"=>:foo, 2=>"foo", 3=>"bar"})))
|
|
134
|
-
t3 = FiniteHashType.new({"a"
|
|
134
|
+
t3 = FiniteHashType.new({"a"=>RDL::Globals.types[:symbol], 2=>RDL::Globals.types[:string]}, RDL::Globals.types[:integer])
|
|
135
135
|
assert (t3.member?({"a"=>:foo, 2=>"foo"}))
|
|
136
136
|
assert (t3.member?({"a"=>:foo, 2=>"foo", two: 2}))
|
|
137
137
|
assert (t3.member?({"a"=>:foo, 2=>"foo", two: 2, three: 3}))
|
|
@@ -139,12 +139,12 @@ class TestMember < Minitest::Test
|
|
|
139
139
|
assert (not (t3.member?({"a"=>:foo, 2=>"foo", two: 2, three: 'three'})))
|
|
140
140
|
assert (not (t3.member?({"a"=>:foo, two: 2})))
|
|
141
141
|
assert (not (t3.member?({2=>"foo", two: 2})))
|
|
142
|
-
t4 = FiniteHashType.new({a:
|
|
142
|
+
t4 = FiniteHashType.new({a: RDL::Globals.types[:symbol], b: RDL::Globals.types[:string]}, RDL::Globals.types[:integer])
|
|
143
143
|
assert (t4.member?(a: :foo, b: "foo"))
|
|
144
144
|
assert (t4.member?(a: :foo, b: "foo", c: 3))
|
|
145
145
|
assert (t4.member?(a: :foo, b: "foo", c: 3, d: 4))
|
|
146
146
|
assert (not (t4.member?(a: :foo, b: "foo", c: "three")))
|
|
147
|
-
t5 = FiniteHashType.new({a:
|
|
147
|
+
t5 = FiniteHashType.new({a: RDL::Globals.types[:symbol], b: OptionalType.new(RDL::Globals.types[:string])}, RDL::Globals.types[:integer])
|
|
148
148
|
assert (t5.member?(a: :foo, b: "foo"))
|
|
149
149
|
assert (t5.member?(a: :foo, b: "foo", c: 3))
|
|
150
150
|
assert (t5.member?(a: :foo, b: "foo", c: 3, d: 4))
|