rdl 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +9 -0
- data/README.md +5 -3
- data/bin/rdl_query +1 -1
- data/lib/rdl/boot_rails.rb +8 -3
- data/lib/rdl/typecheck.rb +17 -12
- data/rdl.gemspec +3 -3
- data/test/test_typecheck.rb +32 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a08748b1afa6ca7710e6bf7c31e1162aa034de66
|
4
|
+
data.tar.gz: 104e8ede0573645fcd3c571000e402875ba94fa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 341fc4e02d341179c93cea2a94c4f60c451a3ff4b5f1b1d7fb7ff01218e5309182e0d421cdbe6eaae1d4d04b00a7dca26f9650d0f8fff55157cf256881a50241
|
7
|
+
data.tar.gz: f38cd8208c3b22ef65ecc317521a28dc03a068b7425d875be9d8df91946a3f5b5caec55cf3940a9a871b76215251305effea50f2b8cf8a448d0f3e221bfde962
|
data/CHANGES.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## [Unreleased]
|
4
4
|
|
5
|
+
## [2.0.1] - 2016-11-11
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
- Improved support for modules (still incomplete)
|
9
|
+
- Fix a bug with typing self.new
|
10
|
+
- Fix bug with annotated return types
|
11
|
+
- Fix bug with rdl_query
|
12
|
+
- Fix bug with running under Rails where type files don't exist (Joel Holdbrooks)
|
13
|
+
|
5
14
|
## [2.0.0] - 2016-08-24
|
6
15
|
### Added
|
7
16
|
- Static type checking!
|
data/README.md
CHANGED
@@ -884,9 +884,7 @@ In Object-Oriented Program Languages and Systems (OOPS) Track at ACM Symposium o
|
|
884
884
|
|
885
885
|
Copyright (c) 2014-2016, University of Maryland, College Park. All rights reserved.
|
886
886
|
|
887
|
-
#
|
888
|
-
|
889
|
-
## Authors
|
887
|
+
# Authors
|
890
888
|
|
891
889
|
* [Jeffrey S. Foster](http://www.cs.umd.edu/~jfoster/)
|
892
890
|
* [Brianna M. Ren](https://www.cs.umd.edu/~bren/)
|
@@ -894,6 +892,10 @@ Copyright (c) 2014-2016, University of Maryland, College Park. All rights reserv
|
|
894
892
|
* Alexander T. Yu
|
895
893
|
* Milod Kazerounian
|
896
894
|
|
895
|
+
# Contributors
|
896
|
+
|
897
|
+
* [Joel Holdbrooks](https://github.com/noprompt)
|
898
|
+
|
897
899
|
# Discussion group
|
898
900
|
|
899
901
|
[RDL Users](https://groups.google.com/forum/#!forum/rdl-users)
|
data/bin/rdl_query
CHANGED
data/lib/rdl/boot_rails.rb
CHANGED
@@ -2,9 +2,14 @@ if Rails.env.development? || Rails.env.test?
|
|
2
2
|
require 'rdl/boot'
|
3
3
|
require 'types/core'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
version = Rails::VERSION::STRING.split('.')[0] + ".x"
|
6
|
+
|
7
|
+
begin
|
8
|
+
require_relative "../types/rails-#{version}/_helpers.rb" # load type aliases first
|
9
|
+
Dir[File.dirname(__FILE__) + "/../types/rails-#{version}/**/*.rb"].each { |f| require f }
|
10
|
+
rescue LoadError
|
11
|
+
$stderr.puts("rdl could not load type definitions for Rails v#{version}")
|
12
|
+
end
|
8
13
|
elsif Rails.env.production?
|
9
14
|
require 'rdl_disable'
|
10
15
|
class ActionController::Base
|
data/lib/rdl/typecheck.rb
CHANGED
@@ -549,6 +549,9 @@ module RDL::Typecheck
|
|
549
549
|
case c
|
550
550
|
when TrueClass, FalseClass, Complex, Rational, Fixnum, Bignum, Float, Symbol, Class
|
551
551
|
[env, RDL::Type::SingletonType.new(c)]
|
552
|
+
when Module
|
553
|
+
t = RDL::Type::SingletonType.new(const_get(e.children[1]))
|
554
|
+
[env, t]
|
552
555
|
else
|
553
556
|
[env, RDL::Type::NominalType.new(const_get(e.children[1]).class)]
|
554
557
|
end
|
@@ -659,10 +662,10 @@ RUBY
|
|
659
662
|
envguards << envi
|
660
663
|
}
|
661
664
|
initial_env = Env.join(e, *envguards)
|
662
|
-
if (tguards.all? { |
|
665
|
+
if (tguards.all? { |typ| typ.is_a?(RDL::Type::SingletonType) && typ.val.is_a?(Class) }) && (e.children[0].type == :lvar)
|
663
666
|
# Special case! We're branching on the type of the guard, which is a local variable.
|
664
667
|
# So rebind that local variable to have the union of the guard types
|
665
|
-
new_typ = RDL::Type::UnionType.new(*(tguards.map { |
|
668
|
+
new_typ = RDL::Type::UnionType.new(*(tguards.map { |typ| RDL::Type::NominalType.new(typ.val) })).canonical
|
666
669
|
# TODO adjust following for generics!
|
667
670
|
if tcontrol.is_a? RDL::Type::GenericType
|
668
671
|
if new_typ == tcontrol.base
|
@@ -761,19 +764,19 @@ RUBY
|
|
761
764
|
end
|
762
765
|
teaches = lookup(scope, tcollect.base.name, :each, e.children[1])
|
763
766
|
inst = tcollect.to_inst.merge(self: tcollect)
|
764
|
-
teaches = teaches.map { |
|
767
|
+
teaches = teaches.map { |typ| typ.instantiate(inst) }
|
765
768
|
else
|
766
769
|
error :for_collection, [tcollect], e.children[1]
|
767
770
|
end
|
768
771
|
teach = nil
|
769
|
-
teaches.each { |
|
772
|
+
teaches.each { |typ|
|
770
773
|
# find `each` method with right type signature:
|
771
774
|
# () { (t1) -> t2 } -> t3
|
772
|
-
next unless
|
773
|
-
next if
|
774
|
-
next unless
|
775
|
-
next unless
|
776
|
-
teach =
|
775
|
+
next unless typ.args.empty?
|
776
|
+
next if typ.block.nil?
|
777
|
+
next unless typ.block.args.size == 1
|
778
|
+
next unless typ.block.block.nil?
|
779
|
+
teach = typ
|
777
780
|
break
|
778
781
|
}
|
779
782
|
error :no_each_type, [tcollect.name], e.children[1] if teach.nil?
|
@@ -1006,6 +1009,7 @@ RUBY
|
|
1006
1009
|
trecvs.each { |trecv|
|
1007
1010
|
trets.concat(tc_send_one_recv(scope, env, trecv, meth, tactuals, block, e))
|
1008
1011
|
}
|
1012
|
+
trets.map! {|t| t.is_a?(RDL::Type::AnnotatedArgType) ? t.type : t}
|
1009
1013
|
return RDL::Type::UnionType.new(*trets)
|
1010
1014
|
end
|
1011
1015
|
|
@@ -1015,9 +1019,8 @@ RUBY
|
|
1015
1019
|
tmeth_inter = [] # Array<MethodType>, i.e., an intersection types
|
1016
1020
|
case trecv
|
1017
1021
|
when RDL::Type::SingletonType
|
1018
|
-
if trecv.val.is_a? Class
|
1019
|
-
|
1020
|
-
ts = lookup(scope, RDL::Util.add_singleton_marker(trecv.val.to_s), name, e)
|
1022
|
+
if trecv.val.is_a? Class or trecv.val.is_a? Module
|
1023
|
+
ts = lookup(scope, RDL::Util.add_singleton_marker(trecv.val.to_s), meth, e)
|
1021
1024
|
ts = [RDL::Type::MethodType.new([], nil, RDL::Type::NominalType.new(trecv.val))] if (meth == :new) && (ts.nil?) # there's always a nullary new if initialize is undefined
|
1022
1025
|
error :no_singleton_method_type, [trecv.val, meth], e unless ts
|
1023
1026
|
inst = {self: trecv}
|
@@ -1243,6 +1246,8 @@ RUBY
|
|
1243
1246
|
klass = RDL::Util.remove_singleton_marker klass
|
1244
1247
|
klass = '(singleton) ' + klass
|
1245
1248
|
end
|
1249
|
+
|
1250
|
+
return nil if the_klass.to_s.start_with?('#<Class:') and name ==:new
|
1246
1251
|
error :missing_ancestor_type, [ancestor, klass, name], e
|
1247
1252
|
end
|
1248
1253
|
}
|
data/rdl.gemspec
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'rdl'
|
7
|
-
s.version = '2.0.
|
8
|
-
s.date = '2016-
|
7
|
+
s.version = '2.0.1'
|
8
|
+
s.date = '2016-11-11'
|
9
9
|
s.summary = 'Ruby type and contract system'
|
10
10
|
s.description = <<-EOF
|
11
11
|
RDL is a gem that adds types and contracts to Ruby. RDL includes extensive
|
@@ -18,5 +18,5 @@ EOF
|
|
18
18
|
s.executables << 'rdl_query'
|
19
19
|
s.homepage = 'https://github.com/plum-umd/rdl'
|
20
20
|
s.license = 'BSD-3-Clause'
|
21
|
-
s.add_runtime_dependency 'parser', '~>2.3', '>= 2.3.1.
|
21
|
+
s.add_runtime_dependency 'parser', '~>2.3', '>= 2.3.1.4'
|
22
22
|
end
|
data/test/test_typecheck.rb
CHANGED
@@ -3,8 +3,20 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
|
|
3
3
|
require 'rdl'
|
4
4
|
require 'types/core'
|
5
5
|
|
6
|
-
class
|
6
|
+
class TestTypecheckC
|
7
|
+
type 'self.bar', '() -> Fixnum or String ret'
|
8
|
+
type 'self.foo', '() -> :A'
|
9
|
+
type 'self.new', '(:D) -> :E'
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestTypecheckD
|
13
|
+
end
|
7
14
|
|
15
|
+
module TestTypecheckM
|
16
|
+
type 'self.foo', '() -> :B'
|
17
|
+
end
|
18
|
+
|
19
|
+
class TestTypecheck < Minitest::Test
|
8
20
|
type :_any_object, "() -> Object" # a method that could return true or false
|
9
21
|
|
10
22
|
def setup
|
@@ -960,7 +972,7 @@ class TestTypecheck < Minitest::Test
|
|
960
972
|
assert_equal @t34, do_tc("begin puts 'foo'; 3; rescue; 4; end", env: @env)
|
961
973
|
assert_equal tt("StandardError or 3"), do_tc("begin puts 'foo'; 3; rescue => e; e; end", env: @env)
|
962
974
|
assert_equal tt("RuntimeError or 3"), do_tc("begin puts 'foo'; 3; rescue RuntimeError => e; e; end", env: @env)
|
963
|
-
assert_equal tt("
|
975
|
+
assert_equal tt("4"), do_tc("begin puts 'foo'; 3; else; 4; end", env: @env) # parser discards else clause!
|
964
976
|
assert_equal tt("RuntimeError or ArgumentError or 3"), do_tc("begin puts 'foo'; 3; rescue RuntimeError => e; e; rescue ArgumentError => x; x; end", env: @env)
|
965
977
|
assert_equal tt("RuntimeError or ArgumentError or 42 or 3"), do_tc("begin puts 'foo'; 3; rescue RuntimeError => e; e; rescue ArgumentError => x; x; else 42; end", env: @env)
|
966
978
|
assert_equal tt("RuntimeError or ArgumentError or 3"), do_tc("begin puts 'foo'; 3; rescue RuntimeError, ArgumentError => e; e; end", env: @env)
|
@@ -1259,4 +1271,22 @@ class TestTypecheck < Minitest::Test
|
|
1259
1271
|
|
1260
1272
|
end
|
1261
1273
|
|
1274
|
+
def test_singleton
|
1275
|
+
assert_equal ':A', do_tc("TestTypecheckC.foo", env: @env).to_s
|
1276
|
+
assert_equal ':B', do_tc("TestTypecheckM.foo", env: @env).to_s
|
1277
|
+
end
|
1278
|
+
|
1279
|
+
def test_annotated_ret
|
1280
|
+
t = $__rdl_parser.scan_str '#T Fixnum or String'
|
1281
|
+
assert_equal t, do_tc("TestTypecheckC.bar", env: @env)
|
1282
|
+
end
|
1283
|
+
|
1284
|
+
def test_constructor
|
1285
|
+
t = do_tc("TestTypecheckC.new(:D)", env: @env)
|
1286
|
+
assert_equal ':E', t.to_s
|
1287
|
+
|
1288
|
+
t = do_tc("TestTypecheckD.new", env: @env)
|
1289
|
+
t2 = RDL::Type::NominalType.new TestTypecheckD
|
1290
|
+
assert_equal t2, t
|
1291
|
+
end
|
1262
1292
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeffrey S. Foster
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-
|
15
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: parser
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
version: '2.3'
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.3.1.
|
26
|
+
version: 2.3.1.4
|
27
27
|
type: :runtime
|
28
28
|
prerelease: false
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '2.3'
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 2.3.1.
|
36
|
+
version: 2.3.1.4
|
37
37
|
description: |
|
38
38
|
RDL is a gem that adds types and contracts to Ruby. RDL includes extensive
|
39
39
|
support for specifying method types, which can either be enforced as
|