├── typed ├── analyzer.common │ ├── script │ │ ├── repl-cljs │ │ ├── repl │ │ ├── test-clj │ │ ├── test-cljs │ │ └── test │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── CHANGELOG.md │ ├── test │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ └── analyzer │ │ │ └── common_test.cljc │ ├── pre-0.8.0-CHANGELOG.md │ ├── src │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ └── analyzer │ │ │ └── common │ │ │ └── passes │ │ │ ├── cleanup.clj │ │ │ └── source_info.clj │ ├── pom.xml │ └── deps.edn ├── checker.jvm │ ├── test │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ └── test │ │ │ ├── reader.clj │ │ │ ├── ann_qualify │ │ │ ├── parent.clj │ │ │ └── child.clj │ │ │ ├── gradual │ │ │ ├── untyped.clj │ │ │ └── import_untyped.clj │ │ │ ├── macro.clj │ │ │ ├── ctyp_294 │ │ │ ├── untyped.clj │ │ │ └── typed.clj │ │ │ ├── mapping_test_file.clj │ │ │ ├── line_number.clj │ │ │ ├── protocol_in_another_ns.clj │ │ │ ├── hello_world.clj │ │ │ ├── for.clj │ │ │ ├── pred_scoping.clj │ │ │ ├── analyze_test.clj │ │ │ ├── def_arrow.clj │ │ │ ├── duplicate_ann.clj │ │ │ ├── binding.clj │ │ │ ├── parse_ast.clj │ │ │ ├── finally.clj │ │ │ ├── fail │ │ │ ├── plain_defprotocol.clj │ │ │ ├── unannotated_record.clj │ │ │ ├── record_no_nil.clj │ │ │ ├── recur_empty_seq.clj │ │ │ ├── recur_non_seq_rest.clj │ │ │ ├── record_as_datatype.clj │ │ │ ├── datatype_as_record.clj │ │ │ ├── CTYP_45.clj │ │ │ ├── record_poly_no_optional.clj │ │ │ └── reflection.clj │ │ │ ├── pred_static.clj │ │ │ ├── promise.clj │ │ │ ├── recur_rest_arg.clj │ │ │ ├── mm_warn_on_unannotated.clj │ │ │ ├── hmap_resolve_assoc.clj │ │ │ ├── CTYP_124_case_update_default.clj │ │ │ ├── CTYP_234 │ │ │ ├── dep.clj │ │ │ └── core.clj │ │ │ ├── var_usage.clj │ │ │ ├── ctyp_263.clj │ │ │ ├── CTYP_101_mapentry.clj │ │ │ ├── nocheck.clj │ │ │ ├── set_bang.clj │ │ │ ├── runtime_check.clj │ │ │ ├── variance_test.clj │ │ │ ├── dyn_propagate.clj │ │ │ ├── unannotated_datatype.clj │ │ │ ├── record_optional_key.clj │ │ │ ├── hvec_dotted.clj │ │ │ ├── datatype_recur.clj │ │ │ ├── protocol_fail.clj │ │ │ ├── warn_on_unannotated_var.clj │ │ │ ├── nested_tfn_operator.clj │ │ │ ├── some_fn.clj │ │ │ ├── project.clj │ │ │ ├── heterogeneous_restarg.clj │ │ │ ├── interop.clj │ │ │ ├── collatz.clj │ │ │ ├── kw_args_undeclared_fail.clj │ │ │ ├── unsound_record.clj │ │ │ ├── shell.clj │ │ │ ├── swap_bang.clj │ │ │ ├── filter_simplify.clj │ │ │ ├── record_poly_map_ctor.clj │ │ │ ├── succeed │ │ │ ├── CTYP_42_record_extend_protocol.clj │ │ │ └── CTYP49_unreachable.clj │ │ │ ├── non_literal_val_fn.clj │ │ │ ├── trampoline.clj │ │ │ ├── protocol_munge.clj │ │ │ ├── load_test.clj │ │ │ ├── data.clj │ │ │ ├── check_tc.clj │ │ │ ├── last_test.clj │ │ │ ├── edn.clj │ │ │ ├── poly.clj │ │ │ ├── mapv_test.clj │ │ │ ├── trans_dots.clj │ │ │ ├── reflect.clj │ │ │ ├── browse.clj │ │ │ ├── person.clj │ │ │ ├── ctyp_284.clj │ │ │ ├── filter_combine.clj │ │ │ ├── ctyp_257.clj │ │ │ ├── bug1.clj │ │ │ ├── get_bounded_tvar.clj │ │ │ ├── protocol_scoping.clj │ │ │ ├── CTYP_37.clj │ │ │ ├── forward_variance.clj │ │ │ ├── error_msg.clj │ │ │ ├── io.clj │ │ │ ├── CTYP_118_cast.clj │ │ │ ├── filter_unit_tests.clj │ │ │ ├── pred_hmap.clj │ │ │ ├── cljc.clj │ │ │ ├── file_mapping.clj │ │ │ ├── util_aliases.clj │ │ │ ├── CTYP146.clj │ │ │ ├── contract_utils_test.clj │ │ │ ├── hsequential.clj │ │ │ ├── symbolic_closures.clj │ │ │ ├── munge_record_field.clj │ │ │ ├── ctyp_258.clj │ │ │ ├── ctyp_255.clj │ │ │ ├── multimethods.clj │ │ │ ├── slow.clj │ │ │ ├── tools_analyzer.clj │ │ │ ├── cast.clj │ │ │ ├── template.clj │ │ │ ├── rec_protocol.clj │ │ │ ├── CTYP_83_performance.clj │ │ │ ├── recursive.clj │ │ │ ├── defprotocol.clj │ │ │ ├── tap.clj │ │ │ ├── records.clj │ │ │ ├── CTYP_144.clj │ │ │ ├── assoc.clj │ │ │ ├── set_test.clj │ │ │ ├── atom.clj │ │ │ ├── ring.clj │ │ │ ├── poly_record.clj │ │ │ ├── pomegranate.clj │ │ │ ├── protocol_untyped_extend.clj │ │ │ ├── protocol.clj │ │ │ ├── csgen_intersection.clj │ │ │ ├── array_old.clj │ │ │ ├── unsound_simplify.clj │ │ │ ├── repl_new.clj │ │ │ ├── tag_test.clj │ │ │ ├── ctyp97_tvar_scoping.clj │ │ │ ├── string.clj │ │ │ └── stacktrace.clj │ ├── script │ │ ├── repl │ │ ├── move-ns.sh │ │ ├── test │ │ ├── current-version.sh │ │ ├── current-coord.sh │ │ └── sync-master.sh │ ├── resources │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ └── test │ │ │ ├── load_file.clj │ │ │ ├── dummy_cljc.cljc │ │ │ ├── duplicated.clj │ │ │ ├── reader_cond.cljc │ │ │ ├── ns_reader_cond.cljc │ │ │ ├── load_file2.clj │ │ │ ├── typed_load │ │ │ ├── eval.clj │ │ │ ├── bad_dep.clj │ │ │ └── uses_bad_dep.clj │ │ │ └── duplicated.cljc │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── bin │ │ └── kaocha │ ├── CHANGELOG.md │ ├── .circleci │ │ └── config.yml │ ├── src │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ ├── checker │ │ │ ├── hset_utils.clj │ │ │ ├── errors_ann.clj │ │ │ ├── indirect_ann.clj │ │ │ ├── coerce_ann.clj │ │ │ ├── check │ │ │ │ ├── local.clj │ │ │ │ ├── binding.clj │ │ │ │ ├── quote.clj │ │ │ │ ├── multi_utils.clj │ │ │ │ ├── set_bang.clj │ │ │ │ ├── multi.clj │ │ │ │ ├── monitor.clj │ │ │ │ └── vector.clj │ │ │ ├── def_utils.clj │ │ │ ├── jvm │ │ │ │ ├── reset_caches.clj │ │ │ │ ├── reflect_utils.clj │ │ │ │ ├── rclass_env.clj │ │ │ │ ├── method_override_env.clj │ │ │ │ ├── method_return_nilables.clj │ │ │ │ ├── ctor_override_env.clj │ │ │ │ └── method_param_nilables.clj │ │ │ ├── indirect_ops.clj │ │ │ ├── nilsafe_utils.clj │ │ │ ├── dvar_env.clj │ │ │ └── ns_options.clj │ │ │ ├── contract_ann.clj │ │ │ └── contrib_annotations.clj │ └── tests.edn ├── .gitignore ├── checker.js │ ├── script │ │ ├── repl │ │ └── test │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── test │ │ └── cljs │ │ │ └── cljs │ │ │ └── core │ │ │ └── typed │ │ │ └── test │ │ │ ├── dep_one.cljs │ │ │ ├── ann.cljs │ │ │ ├── dep_two.cljs │ │ │ ├── goog_import.cljs │ │ │ ├── identity.cljs │ │ │ ├── js_obj.cljs │ │ │ ├── dnolen │ │ │ └── utils │ │ │ │ └── helpers.cljs │ │ │ └── csp.cljs │ ├── CHANGELOG.md │ ├── IDEAS │ ├── README.md │ ├── pom.xml │ └── src │ │ └── clojure │ │ └── core │ │ └── typed │ │ ├── check_ns_cljs.clj │ │ └── analyzer_api_intercept.clj ├── lang.jvm │ ├── script │ │ ├── push-snapshot.sh │ │ ├── repl │ │ ├── test │ │ └── sync-master.sh │ ├── CHANGELOG.md │ ├── pre-0.8.0-CHANGELOG.md │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── test │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ └── lang │ │ │ └── jvm_test.clj │ ├── deps.edn │ ├── pom.xml │ └── README.md ├── analyzer.js │ ├── script │ │ ├── repl │ │ └── test │ ├── CHANGELOG.md │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── pre-0.8.0-CHANGELOG.md │ ├── deps.edn │ └── pom.xml ├── analyzer.jvm │ ├── script │ │ ├── repl │ │ └── test │ ├── CHANGELOG.md │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── pre-0.8.0-CHANGELOG.md │ ├── src │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ └── analyzer │ │ │ └── jvm │ │ │ └── passes │ │ │ └── fix_case_test.clj │ ├── deps.edn │ └── pom.xml ├── annotator.jvm │ ├── script │ │ ├── repl │ │ ├── test │ │ ├── move-ns.sh │ │ └── sync-master.sh │ ├── CHANGELOG.md │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── pre-0.8.0-CHANGELOG.md │ ├── test │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ └── annotator │ │ │ └── test │ │ │ ├── rt_infer │ │ │ ├── loop.clj │ │ │ └── anon_lambda.clj │ │ │ ├── runtime_infer │ │ │ ├── kw_singleton.clj │ │ │ ├── fixed_varargs.clj │ │ │ ├── def_name.clj │ │ │ └── gen_arglists.clj │ │ │ └── spec_infer.clj │ └── src │ │ └── clojure │ │ └── core │ │ └── typed │ │ └── annotator │ │ └── debug_macros.clj ├── lib.clojure │ ├── script │ │ ├── repl │ │ └── test │ ├── CHANGELOG.md │ ├── src │ │ └── typedclojure_config.cljc │ ├── pre-0.8.0-CHANGELOG.md │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── test │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ └── ann_test │ │ │ └── clojure.clj │ ├── pom.xml │ └── README.md ├── lib.core.async │ ├── script │ │ ├── repl │ │ └── test │ ├── src │ │ └── typedclojure_config.cljc │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── CHANGELOG.md │ ├── pom.xml │ ├── deps.edn │ └── README.md ├── runtime.jvm │ ├── script │ │ ├── gen-doc.sh │ │ ├── repl │ │ ├── test │ │ ├── copy-sha │ │ ├── move-ns.sh │ │ ├── gen_doc.clj │ │ └── sync-master.sh │ ├── CHANGELOG.md │ ├── images │ │ └── part-of-typed-clojure-project.png │ ├── src │ │ └── clojure │ │ │ └── core │ │ │ └── typed │ │ │ ├── special_form.clj │ │ │ ├── unsafe.clj │ │ │ ├── env.cljc │ │ │ └── hole.clj │ ├── pom.xml │ └── deps.edn └── README.md ├── doc ├── changelog │ ├── script │ │ ├── gen.sh │ │ └── repl │ ├── deps.edn │ └── changelog.edn ├── images │ ├── become_a_patron_button.png │ ├── donate-to-our-collective.png │ └── part-of-typed-clojure-project.png ├── modules.edn └── notes │ └── unsoundness.txt ├── script ├── repl ├── gen-changelog.sh ├── dev-repl.sh ├── missing-copyright ├── git │ ├── status │ ├── grep │ ├── sync-all │ ├── checkout-branch.sh │ └── clone-all.sh ├── repl-in ├── checkout_branch ├── add-all-missing-copyright ├── deps │ ├── gen-deps-edn │ ├── projects-used-by │ └── projects-that-use ├── start-snapshot.sh ├── bump-readme-version ├── rename-namespace.sh ├── add-copyright └── bump-readme-version.clj ├── dev ├── src │ └── typed │ │ └── dev │ │ └── repl.clj └── deps.edn ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CHANGELOG.md └── .github └── workflows └── clj.yml /typed/analyzer.common/script/repl-cljs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/reader.clj: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /typed/.gitignore: -------------------------------------------------------------------------------- 1 | # generated by script/dev-repl.sh 2 | deps.edn 3 | -------------------------------------------------------------------------------- /typed/checker.js/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL 4 | -------------------------------------------------------------------------------- /typed/lang.jvm/script/push-snapshot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | lein deploy 4 | -------------------------------------------------------------------------------- /typed/lang.jvm/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /doc/changelog/script/gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -m gen-changelog 4 | -------------------------------------------------------------------------------- /doc/changelog/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | clj -A:nREPL 6 | -------------------------------------------------------------------------------- /typed/analyzer.js/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /typed/analyzer.jvm/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /typed/annotator.jvm/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /typed/checker.js/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test:runner 4 | -------------------------------------------------------------------------------- /typed/checker.jvm/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /typed/lang.jvm/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test:runner "$@" 4 | -------------------------------------------------------------------------------- /typed/lib.clojure/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /typed/lib.core.async/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /typed/runtime.jvm/script/gen-doc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -Acodox:test 4 | -------------------------------------------------------------------------------- /typed/runtime.jvm/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /typed/analyzer.common/script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clj -A:test:nREPL "$@" 4 | -------------------------------------------------------------------------------- /typed/analyzer.js/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test:runner "$@" 4 | -------------------------------------------------------------------------------- /typed/analyzer.jvm/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test:runner "$@" 4 | -------------------------------------------------------------------------------- /typed/annotator.jvm/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test:runner "$@" 4 | -------------------------------------------------------------------------------- /typed/lib.core.async/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test:runner "$@" 4 | -------------------------------------------------------------------------------- /typed/runtime.jvm/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test:runner "$@" 4 | -------------------------------------------------------------------------------- /typed/analyzer.common/script/test-clj: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test:runner "$@" 4 | -------------------------------------------------------------------------------- /script/repl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | ./script/repl-in core.typed/checker.jvm "$ARGS" 6 | -------------------------------------------------------------------------------- /typed/lib.clojure/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -xe 4 | 5 | clojure -A:test:runner "$@" 6 | -------------------------------------------------------------------------------- /script/gen-changelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | cd doc/changelog 6 | ./script/gen.sh 7 | -------------------------------------------------------------------------------- /typed/analyzer.common/script/test-cljs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clojure -A:test-cljs:runner-cljs "$@" 4 | -------------------------------------------------------------------------------- /typed/README.md: -------------------------------------------------------------------------------- 1 | This folder contains an autogenerated `deps.edn` file 2 | from `./script/dev-repl.sh`. 3 | -------------------------------------------------------------------------------- /typed/lib.core.async/src/typedclojure_config.cljc: -------------------------------------------------------------------------------- 1 | {:ann #{clojure.core.typed.lib.clojure.core.async}} 2 | -------------------------------------------------------------------------------- /dev/src/typed/dev/repl.clj: -------------------------------------------------------------------------------- 1 | (ns typed.dev.repl 2 | (:gen-class)) 3 | 4 | (defn -main [& args] 5 | (prn "hello")) 6 | -------------------------------------------------------------------------------- /script/dev-repl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | cd dev 6 | clj -A:merge-deps 7 | cd ../typed 8 | clj -A:nREPL 9 | -------------------------------------------------------------------------------- /typed/lang.jvm/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | 5 | -------------------------------------------------------------------------------- /typed/runtime.jvm/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | 5 | -------------------------------------------------------------------------------- /typed/runtime.jvm/script/copy-sha: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # no trailing new line 4 | git rev-parse HEAD | tr -d '\n' | pbcopy 5 | -------------------------------------------------------------------------------- /doc/images/become_a_patron_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/doc/images/become_a_patron_button.png -------------------------------------------------------------------------------- /typed/analyzer.jvm/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | 5 | -------------------------------------------------------------------------------- /typed/annotator.jvm/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | 5 | -------------------------------------------------------------------------------- /typed/lib.clojure/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | 5 | -------------------------------------------------------------------------------- /doc/images/donate-to-our-collective.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/doc/images/donate-to-our-collective.png -------------------------------------------------------------------------------- /typed/lib.clojure/src/typedclojure_config.cljc: -------------------------------------------------------------------------------- 1 | {:ann [clojure.core.typed.ann.clojure] 2 | :ext [clojure.core.typed.ext.clojure.core]} 3 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/load_file.clj: -------------------------------------------------------------------------------- 1 | (ns ^:core.typed clojure.core.typed.test.load-file) 2 | 3 | (inc 'a) 4 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ann_qualify/parent.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ann-qualify.parent) 2 | 3 | (def a 1) 4 | -------------------------------------------------------------------------------- /doc/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/doc/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /script/missing-copyright: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | git grep --files-without-match "Copyright" -- '*.clj' '*.cljs' '*.cljc' '*.java' | grep src/main 4 | -------------------------------------------------------------------------------- /typed/lib.clojure/pre-0.8.0-CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.7.0 - 16 April 2019 2 | 3 | - extracted core Clojure annotations from `core.typed.runtime.jvm` 4 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/gradual/untyped.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.gradual.untyped) 2 | 3 | (def a 1) 4 | (def b nil) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/macro.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.macro) 2 | 3 | (defmacro anything [& a] 4 | `(if 1 ~a 1)) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/dummy_cljc.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.dummy-cljc 2 | (:require [clojure.core.typed :as t])) 3 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/duplicated.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.duplicated 2 | (:require [clojure.core.typed :as t])) 3 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ctyp_294/untyped.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ctyp-294.untyped) 2 | 3 | (def foo inc) 4 | (def bar 1) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/mapping_test_file.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.mapping-test-file) 2 | 3 | (let [a (+ 1 2)] 4 | a) 5 | -------------------------------------------------------------------------------- /typed/analyzer.js/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | - extract from checker.js 5 | 6 | -------------------------------------------------------------------------------- /typed/lang.jvm/pre-0.8.0-CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.7.0 - 2nd December 2018 2 | 3 | - extracted from core.typed.checker.jvm 4 | - renamed c.c.t.lang to c.c.t.lang.jvm 5 | -------------------------------------------------------------------------------- /typed/annotator.jvm/script/move-ns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | git grep -l clojure\.core\.typed\.$1 | xargs sed -i '' "s/clojure\.core\.typed\.$1/clojure.core.typed.$2/g" 4 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/reader_cond.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.reader-cond 2 | (:require [#?(:clj clojure.core.typed) :as t])) 3 | -------------------------------------------------------------------------------- /typed/checker.jvm/script/move-ns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | git grep -l clojure\.core\.typed\.$1 | xargs sed -i '' "s/clojure\.core\.typed\.$1/clojure.core.typed.$2/g" 4 | -------------------------------------------------------------------------------- /typed/lang.jvm/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/lang.jvm/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/runtime.jvm/script/move-ns.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | git grep -l clojure\.core\.typed\.$1 | xargs sed -i '' "s/clojure\.core\.typed\.$1/clojure.core.typed.$2/g" 4 | -------------------------------------------------------------------------------- /typed/analyzer.js/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/analyzer.js/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/checker.js/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/checker.js/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/checker.jvm/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/checker.jvm/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/lib.clojure/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/lib.clojure/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/runtime.jvm/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/runtime.jvm/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/analyzer.jvm/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/analyzer.jvm/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/annotator.jvm/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/annotator.jvm/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/lib.core.async/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/lib.core.async/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/analyzer.common/images/part-of-typed-clojure-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clojure/core.typed/master/typed/analyzer.common/images/part-of-typed-clojure-project.png -------------------------------------------------------------------------------- /typed/checker.js/test/cljs/cljs/core/typed/test/dep_one.cljs: -------------------------------------------------------------------------------- 1 | (ns cljs.core.typed.test.dep-one 2 | (:require [cljs.core.typed :as t :include-macros true])) 3 | 4 | (def a 1) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/bin/kaocha: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -x 4 | 5 | #TODO figure out how to pass extra args to `clojure` 6 | clojure -A:test:kaocha -m kaocha.runner "$@" 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/line_number.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.line-number 2 | (:require [clojure.core.typed :as t])) 3 | 4 | #(identity nil nil) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/protocol_in_another_ns.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.protocol-in-another-ns) 2 | 3 | (defprotocol AnotherNs 4 | (baz [this])) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/ns_reader_cond.cljc: -------------------------------------------------------------------------------- 1 | #?(:clj 2 | (ns clojure.core.typed.test.ns-reader-cond 3 | {:lang :core.typed})) 4 | 5 | #(inc 'a) 6 | -------------------------------------------------------------------------------- /typed/annotator.jvm/pre-0.8.0-CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.7.0 - 17 November 2018 2 | 3 | - split out `org.clojure/core.typed.annotator.jvm` from core.typed, 4 | replacing `org.clojure/core.typed.infer`. 5 | -------------------------------------------------------------------------------- /typed/checker.js/test/cljs/cljs/core/typed/test/ann.cljs: -------------------------------------------------------------------------------- 1 | (ns cljs.core.typed.test.ann 2 | (:require [cljs.core.typed :refer-macros [ann check-ns]])) 3 | 4 | (ann foo number) 5 | (def foo 1) 6 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/load_file2.clj: -------------------------------------------------------------------------------- 1 | (ns ^:core.typed clojure.core.typed.test.load-file2 2 | (:require [clojure.core.typed.test.load-file])) 3 | 4 | (inc 'b) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/hello_world.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.hello-world 2 | (:require [clojure.core.typed :refer [check-ns]])) 3 | 4 | (pr-str "Hello world") 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/for.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.for 2 | (:require [clojure.core.typed :as t :refer [IFn]])) 3 | 4 | (t/for [x :- t/Num, [1 2 3 4]] :- t/Num x) 5 | -------------------------------------------------------------------------------- /script/git/status: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | while read line 6 | do 7 | NAME=`basename ${line}` 8 | cd $NAME 9 | echo $NAME 10 | git status "$@" 11 | cd .. 12 | done < projects 13 | -------------------------------------------------------------------------------- /typed/checker.jvm/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -x 4 | 5 | #clojure -A:test:runner "$@" 6 | 7 | #TODO figure out how to pass extra args to kaocha 8 | clojure -A:test:kaocha "$@" -m kaocha.runner 9 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/pred_scoping.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.pred-scoping 2 | (:require [clojure.core.typed :as unique123 :refer [pred]])) 3 | 4 | (pred unique123/Int) 5 | -------------------------------------------------------------------------------- /script/git/grep: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | while read line 4 | do 5 | NAME=`basename ${line}` 6 | cd $NAME 7 | echo "grepping: $NAME" 8 | git grep "$@" 9 | echo "" 10 | cd .. 11 | done < projects 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/analyze_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.analyze-test 2 | (:require [clojure.core.typed.checker.jvm.analyze-clj :as ana])) 3 | 4 | (let [{:keys [a]} nil]) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/def_arrow.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.def-arrow 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/def a :- Number, 1) 5 | 6 | (assert (= (+ a 1) 2)) 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/duplicate_ann.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.duplicate-ann 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann foo Number) 5 | 6 | (t/ann foo Integer) 7 | -------------------------------------------------------------------------------- /typed/lib.core.async/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | - initial release - extracted core.async annotations from `checker.jvm` 5 | 6 | -------------------------------------------------------------------------------- /typed/checker.js/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | - merge back into monorepo from https://github.com/clojure/core.typed.checker.js 5 | 6 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/typed_load/eval.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.typed-load.eval 2 | {:lang :core.typed} 3 | (:require [clojure.core.typed :as t])) 4 | 5 | (t/cast t/Int nil) 6 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/binding.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.binding 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/def ^:dynamic *foo* :- Boolean, true) 5 | (binding [*foo* false]) 6 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/duplicated.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.duplicated 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ; this is intentional type error for test purposes 5 | (inc 'a) 6 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/typed_load/bad_dep.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.typed-load.bad-dep 2 | {:lang :core.typed}) 3 | 4 | ;; this will only throw a type error on the first load 5 | (inc 'a) 6 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/parse_ast.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.parse-ast 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann-record Top []) 5 | (defrecord Top []) 6 | 7 | (t/defalias A Top) 8 | -------------------------------------------------------------------------------- /typed/runtime.jvm/script/gen_doc.clj: -------------------------------------------------------------------------------- 1 | (ns gen-doc 2 | (:require [codox.main :as codox])) 3 | 4 | (defn -main [& args] 5 | (codox/generate-docs 6 | {:source-paths ["src/main/clojure"] 7 | :output-path "target/doc"})) 8 | -------------------------------------------------------------------------------- /typed/analyzer.common/script/test: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Running analyzer.common tests under Clojure compilation" 4 | ./script/test-clj 5 | echo "Running analyzer.common tests under ClojureScript compilation" 6 | ./script/test-cljs 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/finally.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.finally 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann f [-> String]) 5 | (defn f [] 6 | (try 7 | "a" 8 | (finally 1))) 9 | -------------------------------------------------------------------------------- /typed/lib.clojure/test/clojure/core/typed/ann_test/clojure.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.ann-test.clojure 2 | (:require [clojure.test :refer :all] 3 | [clojure.core.typed :as t])) 4 | 5 | (deftest load-test 6 | (is true)) 7 | -------------------------------------------------------------------------------- /typed/checker.js/test/cljs/cljs/core/typed/test/dep_two.cljs: -------------------------------------------------------------------------------- 1 | (ns cljs.core.typed.test.dep-two 2 | (:require [cljs.core.typed :as t :include-macros true] 3 | [cljs.core.typed.test.dep-one :as one])) 4 | 5 | (def b (inc one/a)) 6 | -------------------------------------------------------------------------------- /script/repl-in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | PROJECT="${1}" 6 | # all but first 7 | ARGS="${@:2}" 8 | 9 | if [ -z $1 ]; then 10 | echo "Must specify submodule" 11 | exit 1 12 | fi 13 | 14 | cd $PROJECT 15 | ./script/repl "$ARGS" 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/plain_defprotocol.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.plain-defprotocol 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ; should throw top level type error 5 | (defprotocol Foo (bar [this])) 6 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/unannotated_record.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.unannotated-record 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ;Should throw a top level type error 5 | (defrecord Unannotated []) 6 | -------------------------------------------------------------------------------- /script/checkout_branch: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | BRANCH=$1 4 | PREFIX="../core.typed-branches" 5 | 6 | if [ -z "$BRANCH" ]; then 7 | echo "Must provide branch name" 8 | exit 1; 9 | fi 10 | 11 | git worktree add -b ${BRANCH} ${PREFIX}/${BRANCH} 12 | -------------------------------------------------------------------------------- /typed/checker.js/test/cljs/cljs/core/typed/test/goog_import.cljs: -------------------------------------------------------------------------------- 1 | (ns cljs.core.typed.test.goog-import 2 | (:require [cljs.core.typed :as t]) 3 | (:import [goog.events EventType])) 4 | 5 | (t/ann et [EventType -> EventType]) 6 | (defn et [e] 7 | e) 8 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/record_no_nil.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.record-no-nil 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann-record Foo [a :- Number]) 5 | (defrecord Foo [a]) 6 | 7 | (map->Foo {}) 8 | -------------------------------------------------------------------------------- /typed/lang.jvm/test/clojure/core/typed/lang/jvm_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.lang.jvm-test 2 | (:require [clojure.core.typed.lang.jvm :as lang] 3 | [clojure.test :refer :all])) 4 | 5 | (deftest stub 6 | (is (map? lang/lang-dispatch))) 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/pred_static.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.pred-static 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (let [a (t/ann-form {:a 1} Any) 5 | _ (assert ((t/pred '{:a Number}) a))] 6 | (+ 1 (:a a))) 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/promise.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.promise 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann p (t/Promise Number)) 5 | (def p (promise)) 6 | 7 | (fn [] 8 | (p 1) 9 | 10 | (inc @p)) 11 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/recur_rest_arg.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.recur-rest-arg 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann recur-args [Number * -> t/Any]) 5 | (defn recur-args 6 | [& args] 7 | (recur args)) 8 | -------------------------------------------------------------------------------- /script/add-all-missing-copyright: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Usage: 4 | # ./script/add-all-missing-copyright 5 | # 6 | # Note: must execute at root of repository. 7 | 8 | for f in $( ./script/missing-copyright ); do 9 | ./script/add-copyright $f 10 | done 11 | -------------------------------------------------------------------------------- /typed/analyzer.common/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | - Renamed clojure.core.typed.analyzer => clojure.core.typed.analyzer.common 5 | - Note: also applies to namespaced keywords 6 | 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/script/current-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | MVN_VERSION=$(mvn -o -q \ 6 | -Dexec.executable=echo \ 7 | -Dexec.args='${project.version}' \ 8 | --non-recursive \ 9 | exec:exec) 10 | 11 | echo $MVN_VERSION 12 | -------------------------------------------------------------------------------- /dev/deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["src"] 2 | :deps {org.clojure/clojure {:mvn/version "1.10.1"}} 3 | :aliases {:merge-deps 4 | {:main-opts ["-m" "typed.dev.merge-deps"]} 5 | :dev-repl 6 | {:main-opts ["-m" "typed.dev.repl"]} 7 | }} 8 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ann_qualify/child.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ann-qualify.child 2 | (:require [clojure.core.typed :as t] 3 | [clojure.core.typed.test.ann-qualify.parent :as p])) 4 | 5 | (t/ann p/a t/Int) 6 | (inc p/a) 7 | -------------------------------------------------------------------------------- /script/git/sync-all: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | function sync_master() { 6 | NAME=`basename $1` 7 | cd $NAME 8 | echo $NAME 9 | ./script/sync-master.sh 10 | cd .. 11 | } 12 | 13 | export -f sync_master 14 | cat projects | parallel sync_master {} 15 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/recur_empty_seq.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.recur-empty-seq 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann recur-args-fail [Number * -> t/Any]) 5 | (defn recur-args-fail [& args] 6 | (recur ())) 7 | -------------------------------------------------------------------------------- /typed/checker.js/test/cljs/cljs/core/typed/test/identity.cljs: -------------------------------------------------------------------------------- 1 | (ns cljs.core.typed.test.identity 2 | (:require [cljs.core.typed :as t])) 3 | 4 | (t/ann my-identity (t/All [x] [x -> (t/U x t/Number)])) 5 | (defn my-identity [x] 6 | (if (number? x) 7 | (inc x) 8 | x)) 9 | -------------------------------------------------------------------------------- /typed/checker.jvm/resources/clojure/core/typed/test/typed_load/uses_bad_dep.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.typed-load.uses-bad-dep 2 | {:lang :core.typed} 3 | ;; this only type checks once, then caches like `require` 4 | (:require [clojure.core.typed.test.typed-load.bad-dep])) 5 | -------------------------------------------------------------------------------- /typed/checker.jvm/script/current-coord.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | MVN_VERSION=$(mvn -o -q \ 6 | -Dexec.executable=echo \ 7 | -Dexec.args='${project.groupId}/${project.artifactId}' \ 8 | --non-recursive \ 9 | exec:exec) 10 | 11 | echo $MVN_VERSION 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/recur_non_seq_rest.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.recur-non-seq-rest 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann recur-args-fail [Number * -> t/Any]) 5 | (defn recur-args-fail [& args] 6 | (recur [1 2 3])) 7 | -------------------------------------------------------------------------------- /typed/analyzer.js/pre-0.8.0-CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.7.1 - 16 April 2019 2 | 3 | - Correct initialize pass :state via `unanalyzed` 4 | 5 | # 0.7.0 - 18 November 2018 6 | 7 | - split out `org.clojure/core.typed.analyzer.jvm` from 8 | core.typed, replacing `org.clojure/core.typed.analyzer` 9 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/record_as_datatype.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.record-as-datatype 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ;Should throw a top level type error 5 | (t/ann-datatype IncorrectRec []) 6 | (defrecord IncorrectRec []) 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/mm_warn_on_unannotated.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.mm-warn-on-unannotated 2 | (:require [clojure.core.typed :as t :refer [check-ns]])) 3 | 4 | (t/warn-on-unannotated-vars) 5 | 6 | (defmulti foo class) 7 | 8 | (defmethod foo Object [a] 1) 9 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/datatype_as_record.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.datatype-as-record 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ;Should throw a top level type error 5 | (clojure.core.typed/ann-record IncorrectDt []) 6 | (deftype IncorrectDt []) 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/hmap_resolve_assoc.clj: -------------------------------------------------------------------------------- 1 | ;CTYP-79 2 | (ns clojure.core.typed.test.hmap-resolve-assoc 3 | (:require [clojure.core.typed :as t])) 4 | 5 | (t/defalias TA (t/HMap :optional {:d t/Any})) 6 | 7 | (t/ann a [TA -> TA]) 8 | (defn a [m] (assoc m :d "foo")) 9 | -------------------------------------------------------------------------------- /typed/checker.js/IDEAS: -------------------------------------------------------------------------------- 1 | 1. Generate TS annotations using https://github.com/fable-compiler/ts2fable 2 | 2. Generate Google Closure annotations using https://github.com/jleyba/js-dossier 3 | 4 | Converting TS->Goog 5 | - https://github.com/honzabrecka/ts-to-goog 6 | - https://github.com/angular/tsickle 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP_124_case_update_default.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP-124-case-update-default 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann case-default [(t/U ':a ':b) -> ':b]) 5 | (defn case-default [e] 6 | (case e 7 | :a :b 8 | e)) 9 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP_234/dep.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP-234.dep 2 | {:core.typed {:collect-only true}} 3 | (:require [clojure.core.typed :as t])) 4 | 5 | (t/defalias MyType 6 | (t/HMap :mandatory {:foo String 7 | :bar t/AnyInteger})) 8 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/var_usage.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.var-usage 2 | (:require [clojure.core.typed :refer [ann check-ns]])) 3 | 4 | (ann foo [Number -> Number]) 5 | (declare foo) 6 | 7 | (ann bar [Number -> Number]) 8 | (defn bar [b] 9 | (+ 2 (foo b))) 10 | -------------------------------------------------------------------------------- /typed/checker.jvm/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | - move `{clojure,cljs}.core.typed.async` to `clojure.core.typed.lib.{clojure,cljs}.core.async` in `core.typed.lib.core.async` submodule 5 | - remove dependency on tools.analyzer 6 | 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP_234/core.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP-234.core 2 | (:require [clojure.core.typed :as t] 3 | [clojure.core.typed.test.CTYP-234.dep :as other])) 4 | 5 | (t/ann foo [other/MyType -> t/AnyInteger]) 6 | (defn foo 7 | [x] 8 | (:bar x)) 9 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ctyp_263.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ctyp-263 2 | (:require [clojure.test :refer :all] 3 | [clojure.core.typed.test.test-utils :refer :all])) 4 | 5 | (deftest catch-type-hint-test 6 | (is-tc-e (try :anything (catch Exception e (.getCause e))))) 7 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP_101_mapentry.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP-101-mapentry 2 | (:require [clojure.core.typed :as t :refer [ann]])) 3 | 4 | (ann f [(clojure.lang.IPersistentMap t/Keyword t/Int) -> (t/Option (clojure.lang.IMapEntry t/Keyword t/Int))]) 5 | (defn f [m] (first m)) 6 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/nocheck.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.nocheck 2 | (:require [clojure.core.typed :refer [ann check-ns]])) 3 | 4 | (ann ^:no-check foo [Number -> Number]) 5 | (defn foo [a] 6 | 'a) 7 | 8 | (ann bar [Number -> Number]) 9 | (defn bar [b] 10 | (+ 2 (foo b))) 11 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/set_bang.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.set-bang 2 | (:import (clojure.lang Keyword)) 3 | (:require [clojure.core.typed :as t])) 4 | 5 | (t/ann foo Keyword) 6 | (def ^:dynamic foo :foo) 7 | 8 | (t/ann bar [-> Keyword]) 9 | (defn bar [] 10 | (set! foo :bar)) 11 | 12 | -------------------------------------------------------------------------------- /typed/checker.js/test/cljs/cljs/core/typed/test/js_obj.cljs: -------------------------------------------------------------------------------- 1 | (ns cljs.core.typed.test.js-obj 2 | (:require [cljs.core.typed :as t])) 3 | 4 | (t/ann jo [-> (t/JSObj {:a t/JSNumber})]) 5 | (defn jo [] 6 | #js {:a 2}) 7 | 8 | #_ 9 | (t/ann jo2 [-> (t/JSObj {:a t/JSNumber})]) 10 | ;; TODO 11 | #_ 12 | (defn jo2 [] 13 | (js-obj :a 2)) 14 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/runtime_check.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.runtime-check 2 | {:lang :core.typed 3 | :core.typed {:features #{:runtime-check}}} 4 | (:require [clojure.core.typed :as t])) 5 | 6 | 7 | (t/ann a t/Int) 8 | (def a 1) 9 | 10 | ;(t/ann b t/Int) 11 | ;(def b nil) 12 | 13 | #(inc nil) 14 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/variance_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.variance-test 2 | (:require [clojure.core.typed :as t])) 3 | 4 | 5 | (t/ann-datatype [[w :variance :contravariant] 6 | [r :variance :covariant]] 7 | FooT 8 | []) 9 | 10 | (deftype FooT []) 11 | -------------------------------------------------------------------------------- /doc/modules.edn: -------------------------------------------------------------------------------- 1 | {:analyzer.common "core/analyzer.common" 2 | :analyzer.jvm "core/analyzer.jvm" 3 | :analyzer.js "core/analyzer.js" 4 | :checker.jvm "core/checker.jvm" 5 | :checker.js "core/checker.js" 6 | :annotator.jvm "util/annotator.jvm" 7 | :lang.jvm "util/lang.jvm" 8 | :lib.clojure "lib/clojure" 9 | :lib.core.async "lib/core.async"} 10 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/dyn_propagate.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.dyn-propagate 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/tc-ignore 5 | (def a {:a 1})) 6 | 7 | (defn b [local] 8 | (let [i a 9 | l (:a a) 10 | id (identity a) 11 | ] 12 | (t/print-env "there") 13 | (inc l))) 14 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/unannotated_datatype.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.unannotated-datatype 2 | (:require [clojure.core.typed :refer [ann tc-ignore check-ns]])) 3 | 4 | (tc-ignore (deftype NoAnnotate [a])) 5 | 6 | (ann test-fn [-> NoAnnotate]) 7 | (defn test-fn [] 8 | (NoAnnotate. 1)) 9 | 10 | (.a (NoAnnotate. 1)) 11 | -------------------------------------------------------------------------------- /typed/checker.js/test/cljs/cljs/core/typed/test/dnolen/utils/helpers.cljs: -------------------------------------------------------------------------------- 1 | (ns cljs.core.typed.test.dnolen.utils.helpers) 2 | 3 | (defn ^{:ann '[Any Any -> Any]} 4 | index-of [xs x] 5 | (let [len (count xs)] 6 | (loop [i 0] 7 | (if (< i len) 8 | (if (= (nth xs i) x) 9 | i 10 | (recur (inc i))) 11 | -1)))) 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/CTYP_45.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.CTYP-45 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ; using defprotocol shouldn't throw an internal error 5 | 6 | (t/ann-protocol MyProto 7 | foo 8 | [MyProto -> nil]) 9 | (defprotocol MyProto 10 | (foo [my-proto])) 11 | -------------------------------------------------------------------------------- /script/deps/gen-deps-edn: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | COMMON=common/deps.edn 6 | OVERRIDES="" 7 | 8 | while read line 9 | do 10 | COORD=$line 11 | NAME=`basename ${COORD}` 12 | OVERRIDES+="\n$COORD {:local/root \"../$NAME\" :deps/manifest :deps}" 13 | done < projects 14 | 15 | echo "{:aliases {:local-deps {:override-deps {$OVERRIDES}}}}" > $COMMON 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/record_optional_key.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.record-optional-key 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann-record Foo [a :- (t/U nil Number)]) 5 | (defrecord Foo [a]) 6 | 7 | (map->Foo {}) 8 | 9 | (t/ann-record FooP [a :- (t/U nil Number)]) 10 | (defrecord FooP [a]) 11 | 12 | (map->FooP {}) 13 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/hvec_dotted.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.hvec-dotted 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (declare vector*) 5 | 6 | (t/ann ^:no-check vector* (t/All [x ...] 7 | [x ... x -> '[x ... x]])) 8 | 9 | (t/ann foo [-> '[Number Number Number]]) 10 | (defn foo [] 11 | (vector* 1 2 3)) 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/datatype_recur.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.datatype-recur 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/defprotocol PBar 5 | (rec [this bar :- t/Num] :- t/Num)) 6 | 7 | (t/ann-datatype Foo []) 8 | (deftype Foo [] 9 | PBar 10 | (rec [this bar] 11 | (if (even? (rand-int 10)) 12 | (recur bar) 13 | bar))) 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *jar 3 | /classes/ 4 | .lein* 5 | *.swp 6 | *.swo 7 | *.aux 8 | *.dvi 9 | *.pdf 10 | *.log 11 | *~ 12 | /.classpath 13 | /.project 14 | /.settings 15 | /bin 16 | .nrepl-port 17 | .repl 18 | .\#* 19 | .idea 20 | **.class 21 | *.iml 22 | .nrepl-port 23 | .DS_Store 24 | .cljs_* 25 | nashorn_* 26 | .cpcache 27 | .rebel_readline_history 28 | junit-output.xml 29 | .cpcache 30 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/protocol_fail.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.protocol-fail 2 | (:require [clojure.core.typed :refer [ann-datatype] :as t])) 3 | 4 | (t/defprotocol AddProtoc 5 | (adder [this amount :- t/Num] :- t/Num)) 6 | 7 | (ann-datatype Accumulator [t :- Number]) 8 | (deftype Accumulator [t] 9 | AddProtoc 10 | (adder [_ i] (Accumulator. (+ t i)))) 11 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/warn_on_unannotated_var.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.warn-on-unannotated-var 2 | (:require [clojure.core.typed :as t :refer [ann check-ns ann-form print-env cf]]) 3 | (:import (clojure.lang IPersistentMap IPersistentVector))) 4 | 5 | (t/warn-on-unannotated-vars) 6 | 7 | (defn foo [a] 8 | (fn [s] (+ s 1))) 9 | 10 | (def bar (+ 1 1.2)) 11 | -------------------------------------------------------------------------------- /doc/notes/unsoundness.txt: -------------------------------------------------------------------------------- 1 | * Unsoundness in core.typed 2 | 3 | core.typed is mostly designed to be a sound type system besides 4 | (at least) these features. 5 | 6 | ** Array-backed seqs 7 | 8 | We assume anything implementing IPersistentCollection is immutable. 9 | 10 | ** Vars 11 | 12 | We assume that vars are always bound, and they are always 13 | set to values of their annotated type. 14 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/record_poly_no_optional.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.record-poly-no-optional 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ; all map->* keys are mandatory in polymorphic records 5 | 6 | (t/ann-record [[foo :variance :invariant]] Foo [b :- (U nil Number)]) 7 | (t/tc-ignore 8 | (defrecord Foo [b]) 9 | ) 10 | 11 | (map->Foo {}) 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/nested_tfn_operator.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.nested-tfn-operator 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/defalias Indirect0 5 | (t/TFn [[x :variance :covariant]] 6 | x)) 7 | 8 | (t/defalias Indirect1 9 | Indirect0) 10 | 11 | (t/ann foo [(Indirect1 Number) -> Number]) 12 | (defn foo [x] 13 | x) 14 | 15 | (foo 1) 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/some_fn.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.some-fn 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (let [s (t/ann-form (some-fn number? symbol?) (predicate (U Number t/Symbol)))] 5 | (t/print-env "f")) 6 | 7 | (let [s (t/ann-form (every-pred symbol? number?) (predicate (I Number t/AnyInteger)))] 8 | (t/print-env "f")) 9 | 10 | (comp :b :a) 11 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/project.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.project 2 | (:require [clojure.core.typed :refer [ann check-ns] :as t])) 3 | 4 | (ann my-atom (t/Atom1 (t/HMap :mandatory {:a t/Num}))) 5 | (def my-atom (atom {:a 1})) 6 | 7 | (ann my-fn (t/All [x a ...] [t/Any x a ... a -> t/Any])) 8 | (defn my-fn [a b & c] 9 | {:a 2}) 10 | 11 | (swap! my-atom my-fn :a 2) 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/heterogeneous_restarg.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.heterogeneous-restarg 2 | (:require [clojure.core.typed :refer [ann check-ns ann-form] 3 | :as t])) 4 | 5 | (ann het-args (t/IFn 6 | [Number -> Number] 7 | [Number Number -> Number])) 8 | (defn het-args [a & [b]] 9 | (cond b (+ a b) 10 | :else a)) 11 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/interop.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.interop 2 | (:import (java.io File)) 3 | (:require [clojure.core.typed :as t])) 4 | 5 | (t/ann f File) 6 | (def f (File. "a")) 7 | 8 | (t/ann prt (t/U nil String)) 9 | (def prt (.getParent ^File f)) 10 | 11 | (t/non-nil-return java.io.File/getName :all) 12 | (t/ann nme String) 13 | (def nme (.getName ^File f)) 14 | -------------------------------------------------------------------------------- /typed/analyzer.common/test/clojure/core/typed/analyzer/common_test.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.analyzer.common-test 2 | (:require #?(:clj [clojure.test :as t] 3 | :cljs [cljs.test :as t] 4 | :default (throw (ex-info "Unknown impl" {}))) 5 | [clojure.core.typed.analyzer.common :as ana])) 6 | 7 | (prn "common test") 8 | 9 | (t/deftest fake-test 10 | (t/is (= 1 1))) 11 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/collatz.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.collatz 2 | (:require [clojure.core.typed :refer [ann] :as t])) 3 | 4 | (ann collatz [Number -> Number]) 5 | (defn collatz [n] 6 | (cond 7 | (= 1 n) 8 | 1 9 | (and (integer? n) 10 | (even? n)) 11 | (collatz (/ n 2)) 12 | :else 13 | (collatz (inc (* 3 n))))) 14 | 15 | (collatz 10) 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/kw_args_undeclared_fail.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.kw-args-undeclared-fail 2 | (:require [clojure.core.typed :as t :refer [ann check-ns ann-form cf]])) 3 | 4 | ;; invoking a kw-fn with undeclared keywords is an error 5 | (ann undeclared-kw-invoke-test [& :optional {:foo t/Any} -> nil]) 6 | (defn undeclared-kw-invoke-test [& a]) 7 | 8 | (undeclared-kw-invoke-test :blah 'a) 9 | -------------------------------------------------------------------------------- /script/git/checkout-branch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | BRANCH=$1 6 | PREFIX="branches" 7 | SCRIPTDIR="script" 8 | 9 | if [ -z "$BRANCH" ]; then 10 | echo "Must provide branch name" 11 | exit 1; 12 | fi 13 | 14 | cp -r $SCRIPTDIR $PREFIX 15 | 16 | while read line 17 | do 18 | NAME=`basename ${line}` 19 | cd ${NAME} 20 | git worktree add -b ${BRANCH} ../${PREFIX}/${BRANCH}/${NAME} 21 | cd .. 22 | done < projects 23 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/unsound_record.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.unsound-record 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann-record Foo [a :- Number]) 5 | (defrecord Foo [a]) 6 | 7 | (t/ann unsound [(t/Map t/Any t/Any) -> Number]) 8 | (defn unsound [r] 9 | (let [r (assoc r :a nil)] 10 | (assert (instance? Foo r)) 11 | (inc (:a r)))) 12 | 13 | (fn [] 14 | (unsound (->Foo 1))) 15 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/shell.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.shell 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all] 5 | [clojure.core.typed.test.destructure])) 6 | 7 | (deftest sh-test 8 | (is-tc-e #(sh) [-> (Map Any Any)] 9 | :requires [[clojure.java.shell :refer [sh]]])) 10 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/swap_bang.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.swap-bang 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann foo (t/Atom1 (t/Map ':a Number))) 5 | (def foo (atom {:a 1})) 6 | 7 | (fn [] 8 | (swap! foo (t/inst assoc (t/Map ':a Number) ':a Number) :a 3)) 9 | 10 | ; 11 | ;(swap! foo (fn [a] a)) 12 | ;(swap! foo (fn [a] a)) 13 | ;(swap! foo (fn [a b] a) 2) 14 | ;(swap! foo (fn [a b] a) 2) 15 | -------------------------------------------------------------------------------- /typed/analyzer.jvm/pre-0.8.0-CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.8.0 - SNAPSHOT 2 | 3 | - Renamed clojure.core.typed.analyzer => clojure.core.typed.analyzer.common 4 | - also applies to namespaced keywords 5 | 6 | # 0.7.1 - 16 April 2019 7 | 8 | - Correct initialize pass :state via `unanalyzed` 9 | 10 | # 0.7.0 - 18 November 2018 11 | 12 | - split out `org.clojure/core.typed.analyzer.jvm` from 13 | core.typed, replacing `org.clojure/core.typed.analyzer` 14 | -------------------------------------------------------------------------------- /typed/analyzer.common/pre-0.8.0-CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.8.0 - SNAPSHOT 2 | 3 | - Renamed clojure.core.typed.analyzer => clojure.core.typed.analyzer.common 4 | - also applies to namespaced keywords 5 | 6 | # 0.7.1 - 16 April 2019 7 | 8 | - Correct initialize pass :state via `unanalyzed` 9 | 10 | # 0.7.0 - 18 November 2018 11 | 12 | - split out `org.clojure/core.typed.analyzer.jvm` from 13 | core.typed, replacing `org.clojure/core.typed.analyzer` 14 | -------------------------------------------------------------------------------- /typed/checker.jvm/.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | jobs: 4 | build: 5 | working_directory: ~/core.typed.checker.jvm 6 | docker: 7 | - image: circleci/openjdk:8-jdk 8 | steps: 9 | - checkout 10 | - run: 11 | command: | 12 | curl -O https://download.clojure.org/install/linux-install.sh 13 | chmod +x linux-install.sh 14 | sudo ./linux-install.sh 15 | - run: ./script/test 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/filter_simplify.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.filter-simplify 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/fn [a :- (t/Nilable (t/NonEmptyVec Number)) 5 | b :- (t/Nilable (t/NonEmptyVec Number))] 6 | (let [a (seq a) 7 | b (seq b) 8 | fa (first a) 9 | fb (first b)] 10 | (t/print-env "before") 11 | (t/print-filterset 12 | "and" 13 | (and a b)))) 14 | -------------------------------------------------------------------------------- /script/start-snapshot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | START=$1 6 | if [ -z $1 ]; then 7 | echo "Must provide folder" 8 | exit 1 9 | fi 10 | 11 | cd $START 12 | COORD=`./script/current-coord.sh` 13 | VERSION=`./script/current-version.sh` 14 | cd .. 15 | 16 | while read line 17 | do 18 | NAME=`basename ${line}` 19 | cd $NAME 20 | echo "grepping: $NAME" 21 | ./script/update-dep.sh $COORD $VERSION 22 | echo "" 23 | cd .. 24 | done < projects 25 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/record_poly_map_ctor.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.record-poly-map-ctor 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ; can omit fields with ground types 5 | 6 | (t/ann-record [[foo :variance :invariant]] Foo [b :- (t/U nil Number) 7 | c :- foo]) 8 | ; FIXME need defrecord> 9 | (t/tc-ignore 10 | (defrecord Foo [b c]) 11 | ) 12 | 13 | (map->Foo {:c 1 :b 2}) 14 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/succeed/CTYP_42_record_extend_protocol.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.succeed.CTYP-42-record-extend-protocol 2 | (:require [clojure.core.typed :as t] 3 | [clojure.repl :as repl])) 4 | 5 | (t/defprotocol PMaths 6 | (mult-by-two [this] :- PMaths)) 7 | 8 | (t/ann-record SpecialNumber [x :- Number]) 9 | (defrecord SpecialNumber [x] 10 | PMaths 11 | (mult-by-two [this] (assoc this :x (* (:x this) 2)))) 12 | -------------------------------------------------------------------------------- /script/bump-readme-version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | VERSION=$1 6 | 7 | if [ -z "$VERSION" ] 8 | then 9 | echo "No new version supplied" 10 | echo "usage: ./script/bump-readme-version " 11 | exit 1 12 | fi 13 | 14 | ./script/bump-readme-version.clj "$VERSION" README.md typed/analyzer.jvm/README.md typed/annotator.jvm/README.md typed/checker.jvm/README.md typed/lang.jvm/README.md typed/lib.clojure/README.md typed/runtime.jvm/README.md 15 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/non_literal_val_fn.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.non-literal-val-fn 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann kw-invoke [t/Kw -> (t/U nil t/Num)]) 5 | (defn kw-invoke [k] 6 | (k {:a 1 :b 2})) 7 | 8 | (t/ann sym-invoke [t/Sym -> (t/U nil t/Num)]) 9 | (defn sym-invoke [k] 10 | (k {:a 1 :b 2})) 11 | 12 | (t/ann either-invoke [(t/U t/Kw t/Sym) -> (t/U nil t/Num)]) 13 | (defn either-invoke [k] 14 | (k {:a 1 :b 2})) 15 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/trampoline.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.trampoline 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (declare funb) 5 | 6 | (t/ann-many [Number -> (t/Rec [f] 7 | (t/U Number [-> (t/U t/Num f)]))] 8 | funa funb) 9 | (defn funa [n] 10 | (if (= n 0) 11 | 0 12 | #(funb (dec n)))) 13 | 14 | (defn funb [n] 15 | (if (= n 0) 16 | 0 17 | #(funa (dec n)))) 18 | 19 | (trampoline funa 100) 20 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/protocol_munge.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.protocol-munge 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/defprotocol Foo 5 | (my_dash [this] :- t/Num)) 6 | 7 | (t/ann-protocol Bar 8 | my_dash_interface [Bar -> t/Symbol]) 9 | (definterface Bar 10 | (my_dash_interface [])) 11 | 12 | (t/ann-datatype FooT []) 13 | (deftype FooT [] 14 | Foo 15 | (my_dash [this] 1) 16 | Bar 17 | (my_dash_interface [this] 'a)) 18 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/load_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.load-test 2 | (:require [clojure.core.typed.load :as load] 3 | [clojure.test :refer :all])) 4 | 5 | ;; ensures evaluation occurs 6 | (deftest evaluation-test 7 | (is (try (load/typed-load1 "clojure/core/typed/test/typed_load/eval") 8 | nil 9 | (catch clojure.lang.ExceptionInfo e 10 | (-> e ex-data :blame :file #{"clojure/core/typed/test/typed_load/eval.clj"}))))) 11 | -------------------------------------------------------------------------------- /typed/annotator.jvm/script/sync-master.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || 4 | branch_name="(unnamed branch)" # detached HEAD 5 | 6 | branch_name=${branch_name##refs/heads/} 7 | 8 | MASTER="master" 9 | 10 | set -e 11 | 12 | if [ $branch_name != "$MASTER" ]; then 13 | echo "Must be on $MASTER" 14 | exit 1; 15 | fi 16 | 17 | git pull clojure --ff-only master 18 | git pull typedclojure --ff-only master 19 | git push typedclojure master 20 | git push clojure master 21 | -------------------------------------------------------------------------------- /typed/lang.jvm/script/sync-master.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || 4 | branch_name="(unnamed branch)" # detached HEAD 5 | 6 | branch_name=${branch_name##refs/heads/} 7 | 8 | MASTER="master" 9 | 10 | set -e 11 | 12 | if [ $branch_name != "$MASTER" ]; then 13 | echo "Must be on $MASTER" 14 | exit 1; 15 | fi 16 | 17 | #git pull clojure --ff-only master 18 | git pull typedclojure --ff-only master 19 | git push typedclojure master 20 | #git push clojure master 21 | -------------------------------------------------------------------------------- /typed/runtime.jvm/script/sync-master.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || 4 | branch_name="(unnamed branch)" # detached HEAD 5 | 6 | branch_name=${branch_name##refs/heads/} 7 | 8 | MASTER="master" 9 | 10 | set -e 11 | 12 | if [ $branch_name != "$MASTER" ]; then 13 | echo "Must be on $MASTER" 14 | exit 1; 15 | fi 16 | 17 | git pull clojure --ff-only master 18 | git pull typedclojure --ff-only master 19 | git push typedclojure master 20 | git push clojure master 21 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/data.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.data 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all])) 5 | 6 | (deftest diff-test 7 | (is-tc-e (diff '[1 2 3] '[1 2]) '[Any Any Any] 8 | :requires [[clojure.data :refer [diff]]]) 9 | (is-tc-err (diff '[1 2 3] '[1 2]) (t/List t/Any ) 10 | :requires [[clojure.data :refer [diff]]])) 11 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/fail/reflection.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.fail.reflection 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/fn [a :- java.io.File] 5 | (.setReadOnly a 1)) 6 | 7 | (t/fn [a :- java.io.File] 8 | (.getName a)) 9 | 10 | (fn [a] 11 | (java.io.File. a)) 12 | 13 | (t/ann write-lines [java.io.Writer (t/Option (t/Coll String)) -> nil]) 14 | (defn write-lines [writer lines] 15 | (t/doseq [l :- String lines] 16 | (.write writer "testing") 17 | (println l))) 18 | -------------------------------------------------------------------------------- /typed/checker.jvm/script/sync-master.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || 4 | branch_name="(unnamed branch)" # detached HEAD 5 | 6 | branch_name=${branch_name##refs/heads/} 7 | 8 | MASTER="master" 9 | 10 | set -e 11 | 12 | if [ $branch_name != "$MASTER" ]; then 13 | echo "Must be on $MASTER" 14 | exit 1; 15 | fi 16 | 17 | git pull clojure --ff-only master --tags 18 | git pull typedclojure --ff-only master 19 | git push typedclojure master --tags 20 | git push clojure master --tags 21 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/check_tc.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.check-tc 2 | (:require [clojure.test :refer :all] 3 | [clojure.core.typed :refer [check-ns]])) 4 | 5 | #_(deftest check-tc 6 | ;fails in hudson 7 | (is (check-ns '[clojure.core.typed.checker.utils 8 | clojure.core.typed.checker.type-rep 9 | clojure.core.typed.checker.cs-rep 10 | clojure.core.typed.checker.name-env 11 | clojure.core.typed.checker.type-ctors]))) 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/last_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.last-test 2 | (:refer-clojure :exclude [fn]) 3 | (:require [clojure.core.typed.test.test-utils :refer :all] 4 | [clojure.test :refer :all] 5 | [clojure.core.typed :as t :refer [ann-form print-env fn]])) 6 | 7 | (deftest last-test 8 | (testing "when we know there is at least one value" 9 | (is-tc-e 10 | (fn [coll :- (NonEmptySeqable Long)] 11 | (let [value (last coll)] 12 | (ann-form value Long)))))) 13 | -------------------------------------------------------------------------------- /doc/changelog/deps.edn: -------------------------------------------------------------------------------- 1 | {:deps {org.clojure/clojure {:mvn/version "1.10.1"}} 2 | :aliases {:gen-changelog 3 | {:main-opts ["-m" "gen-changelog"]} 4 | :nREPL 5 | {:extra-paths [] 6 | :extra-deps 7 | {nrepl/nrepl {:mvn/version "0.6.0"} 8 | cider/cider-nrepl {:mvn/version "0.22.4"}}, 9 | :main-opts ["-m" "nrepl.cmdline" 10 | "--interactive" 11 | "--middleware" "[cider.nrepl/wrap-complete]" 12 | ]}}} 13 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/edn.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.edn 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all] 5 | [clojure.core.typed.test.destructure])) 6 | 7 | (deftest read-string-test 8 | (is-tc-e #(edn/read-string "abc") 9 | :requires [[clojure.edn :as edn]]) 10 | (is-tc-err #(edn/read-string "abc") [-> String] 11 | :requires [[clojure.edn :as edn]])) 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/poly.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.poly 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann repeatedly' 5 | (t/All [x] 6 | (t/IFn 7 | [[-> x] -> (t/Seqable x)] 8 | [t/Int [-> x] -> (t/Seqable x)]))) 9 | (defn repeatedly' 10 | "Takes a function of no args, presumably with side effects, and 11 | returns an infinite (or length n if supplied) lazy sequence of calls 12 | to it" 13 | ([f] (lazy-seq (cons (f) (repeatedly' f)))) 14 | ([n f] (take n (repeatedly' f)))) 15 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/mapv_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.mapv-test 2 | (:refer-clojure :exclude [fn]) 3 | (:require [clojure.core.typed.test.test-utils :refer :all] 4 | [clojure.test :refer :all] 5 | [clojure.core.typed :as t :refer [ann-form print-env fn]])) 6 | 7 | (deftest mapv-test 8 | (testing "when we know the input sequence has values" 9 | (is-tc-e 10 | (fn [coll :- (NonEmptySeqable String)] 11 | (let [result (mapv str coll)] 12 | (ann-form result (CountRange 1))))))) 13 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/trans_dots.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.trans-dots 2 | (:refer-clojure :exclude [defprotocol]) 3 | (:require [clojure.core.typed :as t :refer [defprotocol inst]])) 4 | 5 | (defprotocol [x] Foo) 6 | 7 | (t/ann-datatype [x] Bar []) 8 | (deftype Bar []) 9 | 10 | (t/ann foo (t/All [x b ...] 11 | [(t/U x (Foo x) (Bar x)) ... b -> t/Any])) 12 | (defn foo [& args]) 13 | 14 | ;(defn [x b ...] foo 15 | ; [& args :- (U x Foo) ... b] :- t/Any) 16 | 17 | (inst foo t/Any) 18 | (inst foo t/Any t/Any) 19 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/reflect.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.reflect 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all] 5 | [clojure.core.typed.test.destructure])) 6 | 7 | (deftest type-reflect-test 8 | (is-tc-e #(reflect 1) [-> (Map Any Any)] 9 | :requires [[clojure.reflect :refer [reflect]]]) 10 | (is-tc-err #(reflect 1) [-> String] 11 | :requires [[clojure.reflect :refer [reflect]]])) 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | Typed Clojure is an inclusive project, all are welcome. 4 | 5 | Please respect each other. 6 | 7 | Do not dismiss, abuse, harass, attack, insult or discriminate against others. 8 | 9 | If you feel unwelcome, unsafe, or in danger, please report the incident/s either on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/clojure-core-typed) or by contacting Ambrose Bonnaire-Sergeant via [email](mailto:abonnairesergeant@gmail.com) or [Twitter](https://twitter.com/ambrosebs). We will work with you to resolve the issue promptly. 10 | -------------------------------------------------------------------------------- /script/deps/projects-used-by: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Returns the subprojects in `projects` that the specified project depends on. 4 | 5 | set -e 6 | 7 | PROJECT=$1 8 | 9 | if [ -z $1 ]; then 10 | echo "Must specify project" 11 | exit 1 12 | fi 13 | 14 | cd $PROJECT 15 | TREE=`./script/repl -Stree` 16 | cd .. 17 | 18 | while read line 19 | do 20 | # allow grep to return an error 21 | ISUPSTREAM=`echo "$TREE" | grep "$line "` || true 22 | if [[ $ISUPSTREAM ]]; then 23 | # don't surround by "" so indentation is stripped 24 | echo $ISUPSTREAM 25 | fi 26 | done < projects 27 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/gradual/import_untyped.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.gradual.import-untyped 2 | "Docstring" ;; WARNING don't change the line numbers in this file otherwise tests will fail 3 | {:lang :core.typed} 4 | (:require [clojure.core.typed :as t] 5 | [clojure.core.typed.test.gradual.untyped :as u])) 6 | 7 | (t/untyped-var u/a t/Int) 8 | (t/untyped-var u/b t/Int) 9 | 10 | (t/ann good [:-> t/Int]) 11 | (defn good [] 12 | u/a) 13 | 14 | (t/ann bad [:-> t/Int]) 15 | (defn bad [] 16 | u/b) ;; don't change this line number 17 | 18 | ;#(inc 'a) 19 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/succeed/CTYP49_unreachable.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.succeed.CTYP49-unreachable 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann ^:no-check request 5 | ['{:url String, :method ':get} 6 | -> (t/Atom1 '{:status Number, :body String})]) 7 | (declare request) 8 | 9 | (t/ann get-or-throw [String -> '{:status Number :body String}]) 10 | (defn get-or-throw [url] 11 | (let [doc (request {:url url :method :get}) 12 | doc @doc 13 | _ (if (not= (:status doc) 200) (throw (Exception. (str "Got bad status: " doc))))] 14 | doc)) 15 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/browse.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.browse 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all] 5 | [clojure.core.typed.test.destructure])) 6 | 7 | (deftest browse-url-test 8 | (is-tc-e #(browse-url "www.typedclojure.org") [-> Any] 9 | :requires [[clojure.java.browse :refer [browse-url]]]) 10 | (is-tc-err #(browse-url "www.typedclojure.org") [-> Boolean] 11 | :requires [[clojure.java.browse :refer [browse-url]]])) 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/person.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.person 2 | (:require 3 | [clojure.core.typed :refer [check-ns cf ann-datatype ann 4 | ann-protocol AnyInteger] 5 | :as t])) 6 | 7 | (t/defprotocol Age 8 | (age [this] :- Int)) 9 | 10 | (ann-datatype Person 11 | [name :- String 12 | age :- AnyInteger]) 13 | (deftype Person [name age] 14 | Age 15 | (age [this] age)) 16 | 17 | (age (Person. "Lucy" 34)) 18 | 19 | (ann my-apply (t/All [x y] [[x -> y] x -> y])) 20 | (defn my-apply [f a] 21 | (f a)) 22 | 23 | #_(my-apply age nil) 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ctyp_284.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ctyp-284 2 | (:require [clojure.test :refer :all] 3 | [clojure.core.typed.test.test-utils :refer :all])) 4 | 5 | (deftest transitive-no-reload 6 | (is 7 | (with-typed-load 8 | (and 9 | ; bad dep throws a type error 10 | (try 11 | (require 'clojure.core.typed.test.typed-load.bad-dep :reload) 12 | nil 13 | (catch Throwable _ true)) 14 | ; but isn't rechecked by transitive dep 15 | (nil? (require 'clojure.core.typed.test.typed-load.uses-bad-dep :reload)))))) 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/filter_combine.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.filter-combine 2 | (:require [clojure.core.typed :as t :refer [ann-form check-ns print-filterset]])) 3 | 4 | ; macroexpansion of `or` is understood 5 | (fn [a] 6 | (when (or (string? a) 7 | (symbol? a)) 8 | (ann-form a (t/U t/Sym String)))) 9 | 10 | ;exceptional control flow 11 | (fn [a] 12 | {:pre [(or (string? a) 13 | (symbol? a))]} 14 | (ann-form a (t/U t/Sym String))) 15 | 16 | ;TODO 17 | (comment 18 | (t/fn [a :- (U nil '{:d Number})] 19 | {:pre [(:d a)]} 20 | (ann-form (:d a) Number)) 21 | ) 22 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ctyp_257.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ctyp-257 2 | (:require [clojure.test :refer :all] 3 | [clojure.core.typed.checker.type-rep :as r] 4 | [clojure.core.typed.checker.type-ctors :as c] 5 | [clojure.core.typed.test.test-utils :refer :all])) 6 | 7 | (deftest empty-intersection-test 8 | (testing "empty intersection should be Top, not Bottom" 9 | (is (= (c/make-Intersection []) r/-any)) 10 | (is (= (c/In) r/-any))) 11 | (testing "intersection containing Bottom is Bottom" 12 | (is (= (c/In r/-nothing r/-any) 13 | r/-nothing)))) 14 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/bug1.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.bug1 2 | (:require [clojure.core.typed :as t] 3 | [clojure.core.typed.checker.type_rep]) 4 | (:import [clojure.core.typed.checker.type_rep Result] 5 | [clojure.lang Keyword])) 6 | 7 | (t/ann *frees-mode* (t/U nil t/Kw)) 8 | (def ^:dynamic *frees-mode* nil) 9 | 10 | (t/ann frees [t/Any -> t/Any]) 11 | (defmulti ^:private frees (fn [t] [*frees-mode* (class t)])) 12 | 13 | (defmethod frees [::any-var Result] 14 | [t] 15 | (t/print-env "before") 16 | (t/ann-form t Result) 17 | (let [{:keys [t fl o]} t] 18 | (t/print-env "after"))) 19 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/get_bounded_tvar.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.get-bounded-tvar 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/defalias QuilSketch Number) 5 | 6 | (t/ann-record InkwellSketch [running? :- (t/Atom1 Boolean)]) 7 | (defrecord InkwellSketch [running?]) 8 | 9 | ; free variables bounded by a record 10 | (t/ann stop (t/All [[x :< InkwellSketch]] [x -> x])) 11 | (defn stop [sketch] 12 | (reset! (:running? sketch) false) 13 | sketch) 14 | 15 | ; free variables bounded by a HMap 16 | (t/ann f1 (t/All [[x :< '{:a (t/Atom1 Boolean)}]] [x -> x])) 17 | (defn f1 [h] 18 | (reset! (:a h) false) 19 | h) 20 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/protocol_scoping.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.protocol-scoping 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/defprotocol NonPoly 5 | (nonpoly [this])) 6 | 7 | (t/ann-datatype DNP []) 8 | (deftype DNP [] 9 | NonPoly 10 | (nonpoly [this] this)) 11 | 12 | (t/defprotocol 13 | [[foo :variance :covariant]] 14 | Foo 15 | (bar- [this] :- foo)) 16 | 17 | (t/ann-datatype FooD [t :- t/Symbol] 18 | :extends 19 | [(Foo t/Symbol)]) 20 | 21 | (deftype FooD [t] 22 | Foo 23 | (bar- [this] t)) 24 | 25 | (t/ann-form (bar- (->FooD 'a)) 26 | t/Symbol) 27 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP_37.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP-37 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ; this used to fail with jvm.tools.analyzer, now seems 5 | ; to type check successfully with tools.analyzer.jvm 6 | 7 | (t/defprotocol PProcess 8 | (stop [system] :- PProcess 9 | "Runs side effects to stop the process. Returns the process.")) 10 | 11 | (t/ann-record Logger [in :- t/Any 12 | out-listener :- t/Any 13 | stop :- t/Any]) 14 | (defrecord Logger [in out-listener stop] 15 | PProcess 16 | (stop [{:keys [stop] :as logger}] 17 | logger)) 18 | 19 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/forward_variance.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.forward-variance 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ; # Problem 5 | ; 6 | ; 7 | 8 | ; TODO what happens if (def Foo) occurs in this namespaces? 9 | ;(t/declare-datatypes 10 | ; [Foo :variances [:covariant :invariant]] 11 | ; Bar) 12 | ; 13 | ;(t/declare-aliases 14 | ; [Foo :variances [:covariant :invariant] 15 | ; :rank [* * -> *]]) 16 | ; 17 | 18 | ;(binding [t/*collect-on-eval* false] 19 | ;(t/ann-datatype [[x :variance :covariant 20 | ; :< (Foo Any Any)]] 21 | ; Bar) 22 | ; 23 | ;(t/ann-datatype Foo) 24 | ;) 25 | -------------------------------------------------------------------------------- /typed/runtime.jvm/src/clojure/core/typed/special_form.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^:no-doc clojure.core.typed.special-form) 10 | 11 | (def special-form ::special-form) 12 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/error_msg.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.error-msg 2 | (:require 3 | ; this loads the type system, must go first 4 | [clojure.core.typed.test.test-utils :refer :all] 5 | [clojure.test :refer :all] 6 | [clojure.core.typed :as t :refer [check-ns 7 | check-ns-info]])) 8 | 9 | (deftest invoke-line-number 10 | (is (= 11 | {:line 4 :column 2} 12 | (-> (check-ns-info 'clojure.core.typed.test.line-number) 13 | :delayed-errors 14 | first 15 | ex-data 16 | :env 17 | (select-keys [:line :column]))))) 18 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/io.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.io 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all] 5 | [clojure.core.typed.test.destructure])) 6 | 7 | (deftest delete-file-test 8 | (is-tc-e #(delete-file "abc") [-> Any] 9 | :requires [[clojure.java.io :refer [delete-file]]]) 10 | (is-tc-e #(delete-file "abc" true) [-> Any] 11 | :requires [[clojure.java.io :refer [delete-file]]]) 12 | (is-tc-err #(delete-file "abc") String 13 | :requires [[clojure.java.io :refer [delete-file]]])) 14 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP_118_cast.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP-118-cast 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann i1 String) 5 | (def i1 (cast String "a")) 6 | 7 | (t/ann i2 (t/I String (t/Value "a"))) 8 | (def i2 (let [x String] (cast x "a"))) 9 | 10 | (t/ann i3 (t/I String (t/Value "c"))) 11 | (def i3 ((t/fn [x :- Class y :- (t/Value "c")] (cast x y)) String "c")) 12 | 13 | (t/ann foo Class) 14 | (def foo String) 15 | 16 | (t/ann v (t/I String (t/Value "b"))) 17 | (def v (cast foo "b")) 18 | 19 | (t/ann v1 Class) 20 | (def v1 (cast (t/ann-form Class Class) (class :any))) 21 | 22 | (t/ann v2 String) 23 | (def v2 (cast (if true String nil) "c")) 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/filter_unit_tests.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.filter-unit-tests 2 | (:require [clojure.core.typed.test.test-utils :refer :all] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.checker.filter-ops :refer :all] 5 | [clojure.core.typed.checker.path-rep :refer :all] 6 | [clojure.core.typed.checker.type-ctors :refer :all])) 7 | 8 | (deftest refine-branch-test 9 | (is-tc-e (do 10 | (defalias M (U '{:a Int} 11 | '{:a Sym})) 12 | (fn [a :- M] 13 | (if (symbol? (:a a)) 14 | (ann-form (:a a) Sym) 15 | (ann-form (:a a) Int)))))) 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/pred_hmap.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.pred-hmap 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/defalias Cow '{:type ':cow}) 5 | (t/defalias Pig '{:type ':pig}) 6 | (t/defalias Animal (t/U Cow Pig)) 7 | 8 | (t/ann in-the-barn '[Animal Animal *]) 9 | (def in-the-barn [{:type :cow} {:type :pig}]) 10 | 11 | ;; Could cow? have automatic annotations, as it comes from core.typed? 12 | (t/ann cow? (t/Pred Cow)) 13 | (def cow? (t/pred Cow)) 14 | 15 | (t/ann cow-moo [Cow -> nil]) 16 | (defn cow-moo [cow]) 17 | 18 | (t/ann pig-oink [Pig -> nil]) 19 | (defn pig-oink [pig]) 20 | 21 | (let [a (first in-the-barn)] 22 | (if (cow? a) 23 | (cow-moo a) 24 | (pig-oink a))) 25 | -------------------------------------------------------------------------------- /typed/annotator.jvm/test/clojure/core/typed/annotator/test/rt_infer/loop.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.annotator.test.rt-infer.loop 2 | {:lang :core.typed 3 | :core.typed {:features #{:runtime-infer}}} 4 | (:require [clojure.core.typed :as t])) 5 | 6 | (defn b [coll] 7 | (loop [c coll, out []] 8 | (if (seq c) 9 | (recur (next c) (conj out (inc (first c)))) 10 | out))) 11 | 12 | (b [1 2 3 4 5]) 13 | 14 | ;(defn c [coll] 15 | ; (loop [[:as c] coll 16 | ; out [] 17 | ; {:as nothing} {}] 18 | ; (if (seq c) 19 | ; (recur (next c) (conj out (inc (first c))) nil) 20 | ; out))) 21 | ; 22 | ;(c [1 2 3 4 5]) 23 | 24 | (doall 25 | (for 26 | [a [1 2] 27 | b [2 3]] 28 | [a b]) 29 | ) 30 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/hset_utils.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.hset-utils) 10 | 11 | (def valid-fixed? (some-fn string? symbol? keyword? nil? number? 12 | char? boolean?)) 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-SNAPSHOT 3 | 4 | ## checker.jvm 5 | 6 | - move `{clojure,cljs}.core.typed.async` to `clojure.core.typed.lib.{clojure,cljs}.core.async` in `core.typed.lib.core.async` submodule 7 | - remove dependency on tools.analyzer 8 | 9 | ## lib.core.async 10 | 11 | - initial release - extracted core.async annotations from `checker.jvm` 12 | 13 | ## analyzer.common 14 | 15 | - Renamed clojure.core.typed.analyzer => clojure.core.typed.analyzer.common 16 | - Note: also applies to namespaced keywords 17 | 18 | ## analyzer.js 19 | 20 | - extract from checker.js 21 | 22 | ## checker.js 23 | 24 | - merge back into monorepo from https://github.com/clojure/core.typed.checker.js 25 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/cljc.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.cljc 2 | (:require [clojure.test :refer :all] 3 | [clojure.core.typed :as t] 4 | [clojure.core.typed.load :as load])) 5 | 6 | (deftest check-ns-should-load-cljc-files 7 | (is (t/check-ns 'clojure.core.typed.test.dummy-cljc))) 8 | 9 | (deftest check-ns-should-load-clj-files-before-cljc 10 | (is (t/check-ns 'clojure.core.typed.test.duplicated))) 11 | 12 | (deftest CTYP-285-ns-form-in-reader-cond-should-work 13 | (is (thrown? 14 | clojure.lang.ExceptionInfo 15 | (load/typed-load1 "clojure/core/typed/test/ns_reader_cond")))) 16 | 17 | (deftest allow-reader-conditional-in-ns-form 18 | (is (t/check-ns 'clojure.core.typed.test.reader-cond))) 19 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/file_mapping.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.file-mapping 2 | (:require 3 | ; this loads the type system, must go first 4 | [clojure.core.typed.test.test-utils :refer [check clj]] 5 | [clojure.core.typed.checker.jvm.analyze-clj :as ana] 6 | [clojure.core.typed :as t] 7 | [clojure.core.typed.checker.jvm.check :as chk])) 8 | 9 | #_(-> (ana/ast-for-form '(let [a (+ 1 2)] a)) :env ((juxt :line :column))) 10 | 11 | #_(-> (ana/ast-for-form '(let [{:as a} {}] a)) :env ((juxt :line :column))) 12 | 13 | 14 | #_(clj 15 | (clojure.pprint/pprint 16 | (:file-mapping 17 | (t/check-ns-info 'clojure.core.typed.test.mapping-test-file 18 | :file-mapping true)))) 19 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/util_aliases.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.util-aliases 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/defalias MyName (t/HMap :mandatory {:a (t/Value 1)})) 5 | (t/defalias MapName (t/HMap :mandatory {:a MyName})) 6 | (t/defalias MapStruct1 (t/HMap :mandatory {:type (t/Value :MapStruct1) 7 | :a MyName})) 8 | (t/defalias MapStruct2 (t/HMap :mandatory {:type (t/Value :MapStruct2) 9 | :b MyName})) 10 | (t/defalias UnionName (t/U MapStruct1 MapStruct2)) 11 | 12 | (t/defalias HMapAlias1 '{:a t/Num}) 13 | (t/defalias HMapAlias2 '{:b t/Num}) 14 | (t/defalias HMapAliasInt1 '{:foo t/Int}) 15 | (t/defalias HMapAliasStr2 '{:bar t/Str}) 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP146.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP146 2 | (:require [clojure.core.typed :refer [ann] :as t])) 3 | 4 | (ann distinct-except 5 | (t/All [x] 6 | [[x -> Boolean] (t/Option (t/I clojure.lang.Sequential (t/Seq x))) -> (t/Seq x)])) 7 | (defn distinct-except 8 | "Same as distinct, but keeps duplicates if they pass exception?" 9 | [exception? [head & tail :as coll]] 10 | (lazy-seq 11 | (when head 12 | (cons head 13 | (distinct-except exception? 14 | (if (exception? head) 15 | (when tail (cast clojure.lang.Sequential tail)) 16 | (cast clojure.lang.Sequential (remove (partial = head) tail)))))))) 17 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/contract_utils_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.contract-utils-test 2 | (:refer-clojure :exclude [boolean?]) 3 | (:require [clojure.core.typed.test.test-utils :refer :all] 4 | [clojure.test :refer :all] 5 | [clojure.core.typed.contract-utils :as con :refer :all])) 6 | 7 | (deftest hmap-c-test 8 | (is ((hmap-c?) 9 | {})) 10 | (is (not ((hmap-c?) 11 | nil))) 12 | (is ((hmap-c? :k symbol?) 13 | {:k 'a})) 14 | (is (not ((hmap-c? :k symbol?) 15 | {}))) 16 | (is ((hmap-c? (optional :k) symbol?) 17 | {:k 'a})) 18 | (is (not ((hmap-c? (optional :k) symbol?) 19 | {:k :a}))) 20 | (is ((hmap-c? (optional :k) symbol?) 21 | {}))) 22 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/hsequential.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.hsequential 2 | (:require [clojure.core.typed :as t])) 3 | 4 | ; currently we can't test if (HSequential [z t/Any *]) is subtype of 5 | ; (HSequential [x y ... y]) or not, because we can't compare free variable 6 | (t/ann first-number [(t/HSequential [Number t/Any *]) -> Number]) 7 | (defn first-number [l] (first l)) 8 | 9 | ; NOTE don't write code like this, we assume one argument corresponding to one type 10 | (t/ann test-target (t/All [y ...] [Number y ... y -> (t/U nil Number)])) 11 | (defn test-target [& y] (when-not (empty? y) (first-number y))) 12 | 13 | #_(t/defn [y ...] test-target2 14 | [& y :- y ... y] :- (t/U nil Number) 15 | (when-not (empty? y) (first-number y))) 16 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/symbolic_closures.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.symbolic-closures 2 | (:require 3 | [clojure.core.typed.test.test-utils :refer :all] 4 | [clojure.core.typed.checker.type-rep :as r] 5 | [clojure.test :refer :all])) 6 | 7 | (when r/enable-symbolic-closures? 8 | (deftest symbolic-closure-test 9 | (tc-e (let [f (fn* [x] x)] 10 | (f 1))) 11 | (tc-e (let [f (fn* [x] x)] 12 | (f 1)) 13 | Int) 14 | (tc-err (let [f (fn* [x] x)] 15 | (f 1)) 16 | Bool) 17 | #_ 18 | (tc-e (let [comp (fn* [f g] (fn* [x] (f (g x)))) 19 | f (fn* [x] x) 20 | g (fn* [y] y)] 21 | ((comp f g) 1)) 22 | ) 23 | )) 24 | -------------------------------------------------------------------------------- /typed/annotator.jvm/test/clojure/core/typed/annotator/test/runtime_infer/kw_singleton.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.annotator.test.runtime-infer.kw-singleton 2 | {:lang :core.typed 3 | :core.typed {:features #{:runtime-infer}} 4 | } 5 | (:require [clojure.core.typed :as t] 6 | [clojure.spec.alpha :as s] 7 | [clojure.pprint :refer [pprint]])) 8 | 9 | ;; Start: Generated by clojure.core.typed - DO NOT EDIT 10 | (s/def ::a #{:e :c :b :d :f}) 11 | (s/def ::AMap (s/keys :req [::a])) 12 | (s/fdef single-out :args (s/cat) :ret ::AMap) 13 | ;; End: Generated by clojure.core.typed - DO NOT EDIT 14 | (defn single-out [] 15 | (rand-nth 16 | [{::a :b} 17 | {::a :c} 18 | {::a :d} 19 | {::a :e} 20 | {::a :f}])) 21 | 22 | (dotimes [_ 100] 23 | (single-out)) 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/munge_record_field.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.munge-record-field 2 | (:require [clojure.core.typed :as t :refer [ann check-ns ann-form print-env cf ann-record ann-datatype]])) 3 | 4 | (ann-datatype FooDT [normal :- Number 5 | other-keys? :- Number]) 6 | (deftype FooDT [normal other-keys?]) 7 | 8 | ; don't eval this; see CLJ-979 9 | (fn [] 10 | (ann-form (.normal ^FooDT (->FooDT 2 1)) Number) 11 | ) 12 | 13 | (ann-record FooRec [other-keys? :- Number]) 14 | (defrecord FooRec [other-keys?]) 15 | 16 | ; don't eval this; see CLJ-979 17 | (fn [] 18 | (ann-form (.other-keys? ^FooDT (->FooDT 2 1)) Number) 19 | 20 | (ann-form (:other-keys? (->FooRec 1)) Number) 21 | (ann-form (.other-keys? ^FooRec (->FooRec 1)) Number) 22 | ) 23 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ctyp_258.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ctyp-258 2 | (:require [clojure.test :refer :all] 3 | [clojure.core.typed.checker.type-rep :refer :all] 4 | [clojure.core.typed.checker.filter-rep :refer :all] 5 | [clojure.core.typed.checker.filter-ops :refer :all] 6 | [clojure.core.typed.test.test-utils :refer :all])) 7 | 8 | (deftest ctyp-258-test 9 | (testing "(is Any ..) = tt" 10 | (is (= (-filter -any 'a) 11 | -top))) 12 | (testing "(is Nothing ..) = ff" 13 | (is (= (-filter -nothing 'a) 14 | -bot))) 15 | (testing "(! Any ..) = ff" 16 | (is (= (-not-filter -any 'a) 17 | -bot))) 18 | (testing "(! Nothing ..) = tt" 19 | (is (= (-not-filter -nothing 'a) 20 | -top)))) 21 | -------------------------------------------------------------------------------- /doc/changelog/changelog.edn: -------------------------------------------------------------------------------- 1 | [["0.8.0" 2 | [:checker.jvm 3 | "move `{clojure,cljs}.core.typed.async` to `clojure.core.typed.lib.{clojure,cljs}.core.async` in `core.typed.lib.core.async` submodule" 4 | "remove dependency on tools.analyzer"] 5 | [:lib.core.async 6 | "initial release - extracted core.async annotations from `checker.jvm`"] 7 | [:lib.clojure 8 | "rename namespace: clojure.core.typed.lib.clojure => clojure.core.typed.ann.clojure"] 9 | [:analyzer.common 10 | ["Renamed clojure.core.typed.analyzer => clojure.core.typed.analyzer.common" 11 | ["Note: also applies to namespaced keywords"]]] 12 | [:analyzer.js 13 | "extract from checker.js"] 14 | [:checker.js 15 | "merge back into monorepo from https://github.com/clojure/core.typed.checker.js"] 16 | #_[:changelog/all 17 | ]] 18 | ] 19 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ctyp_255.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ctyp-255 2 | (:require [clojure.test :refer :all] 3 | [clojure.core.typed.checker.jvm.parse-unparse :refer :all] 4 | [clojure.core.typed.checker.type-rep :as r] 5 | [clojure.core.typed.checker.type-ctors :as c] 6 | [clojure.core.typed :as t] 7 | [clojure.core.typed.checker.init :as init] 8 | [clojure.core.typed.test.test-utils :refer :all])) 9 | 10 | (deftest ctyp-255-test 11 | (testing "unknown implementation of unparse uses clojure.core.typed 12 | for special types" 13 | (is (= (unparse-type r/-any) 14 | 'clojure.core.typed/Any))) 15 | (testing "can print a tc-e result with :unknown" 16 | (is (do (prn (tc-e 1)) 17 | true)))) 18 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ctyp_294/typed.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ctyp-294.typed 2 | {:lang :core.typed 3 | :core.typed {:experimental #{:infer-vars 4 | :infer-locals}}} 5 | (:require 6 | [clojure.core.typed :as t] 7 | [clojure.core.typed.test.ctyp-294.untyped :as u])) 8 | 9 | #(inc (t/ann-form u/bar t/Int)) 10 | 11 | #(inc (u/foo 1)) 12 | 13 | ;#_#(inc (u/foo (inc 'a))) 14 | 15 | (t/ann bar (t/IFn ;[t/Str :-> t/Str] 16 | [t/Int :-> t/Int])) 17 | (defn bar [x] 18 | x) 19 | 20 | #(inc (bar (t/ann-form u/foo t/Int))) 21 | 22 | (map inc [u/bar]) 23 | 24 | (fn [a] (inc a)) 25 | (filter (fn [a] (inc a)) [1 2 3]) 26 | (filter (fn [a] 27 | {:pre [(integer? a)]} 28 | (inc a)) 29 | [1 2 3]) 30 | (inc @#'u/bar) 31 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/errors_ann.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.errors-ann 10 | (:require [clojure.core.typed :as t])) 11 | 12 | (t/ann ^:no-check clojure.core.typed.errors/deprecated-warn [String -> nil]) 13 | (t/ann ^:no-check clojure.core.typed.errors/int-error [String -> t/Nothing]) 14 | 15 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/multimethods.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.multimethods 2 | (:require [clojure.core.typed.test.test-utils :refer :all] 3 | [clojure.core.typed :refer [check-ns]] 4 | [clojure.test :refer :all])) 5 | 6 | (deftest multimethod-test 7 | (is (check-ns 'clojure.core.typed.test.mm)) 8 | (is-tc-e (do (ann f [Any -> Any]) 9 | (defmulti f class) 10 | (defmethod f Number [n] (inc n)))) 11 | (is-tc-e (do (ann f [Any -> Any]) 12 | (defmulti f (fn [a] (class a))) 13 | (defmethod f Number [n] (inc n)))) 14 | (is-tc-e (do (ann f [Any Any -> Any]) 15 | (defmulti f (fn [a b] 16 | [(class a) (class b)])) 17 | (defmethod f [Number Number] [n1 n2] (+ n1 n2))))) 18 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/slow.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.slow 2 | (:require 3 | [clojure.core.typed :refer [ann defalias] 4 | :as t])) 5 | 6 | (defalias VersionVector (t/NonEmptyVec Number)) 7 | (ann version-less [(t/U nil VersionVector) (t/U nil VersionVector) -> boolean]) 8 | (defn version-less 9 | "Compare two version vectors." 10 | [v1 v2] 11 | (t/loop [v1 :- (t/NilableNonEmptySeq Number) (seq v1) 12 | v2 :- (t/NilableNonEmptySeq Number) (seq v2)] 13 | (let [fv1 (first v1) 14 | fv2 (first v2)] 15 | (cond 16 | (and (not v1) (not v2)) false 17 | (and v1 (not v2)) false 18 | (or (and (not v1) v2) 19 | (and fv1 fv2 (< fv1 fv2))) true 20 | (and fv1 fv2 (> fv1 fv2)) false 21 | :else (recur (next v1) (next v2)))))) 22 | 23 | -------------------------------------------------------------------------------- /typed/checker.js/README.md: -------------------------------------------------------------------------------- 1 | # core.typed.checker.js 2 | 3 | 4 | 5 | Type checker for Typed Clojure, for ClojureScript on JS. 6 | 7 | ## YourKit 8 | 9 | YourKit is kindly supporting core.typed and other open source projects with its full-featured Java Profiler. 10 | YourKit, LLC is the creator of innovative and intelligent tools for profiling 11 | Java and .NET applications. Take a look at YourKit's leading software products: 12 | 13 | * YourKit Java Profiler and 14 | * YourKit .NET Profiler. 15 | 16 | ## License 17 | 18 | Copyright © Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 19 | 20 | Licensed under the EPL (see the file epl-v10.html). 21 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/tools_analyzer.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.tools-analyzer 2 | (:require [clojure.core.typed :as t] 3 | [clojure.core.typed.checker.jvm.analyze-clj :as ana] 4 | #_[clojure.core.typed.checker.utils :as u] 5 | #_[clojure.core.typed.current-impl :as impl])) 6 | 7 | #_(comment 8 | (defprotocol D) 9 | 10 | (-> 11 | (ana/ast-for-form 12 | '(letfn [(a [c] b) 13 | (b [c] a)])) 14 | :bindings 15 | first 16 | :init 17 | :methods 18 | first 19 | :body 20 | :ret 21 | :name 22 | ) 23 | 24 | (impl/with-clojure-impl 25 | (u/emit-form-fn 26 | (ana/ast-for-form 27 | '(fn a [b]) 28 | ))) 29 | ) 30 | 31 | ;; records 32 | (deftype FooDT3 []) 33 | (assert (cast FooDT3 (->FooDT3))) 34 | ;(assert (instance? FooDT (->FooDT))) 35 | ;(.normal ^FooDT (->FooDT 2 1)) 36 | -------------------------------------------------------------------------------- /typed/annotator.jvm/test/clojure/core/typed/annotator/test/runtime_infer/fixed_varargs.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.annotator.test.runtime-infer.fixed-varargs 2 | {:lang :core.typed 3 | :core.typed {:features #{:runtime-infer}} 4 | } 5 | (:require [clojure.core.typed :as t] 6 | [clojure.spec.alpha :as s] 7 | [clojure.pprint :refer [pprint]])) 8 | 9 | ;; Start: Generated by clojure.core.typed - DO NOT EDIT 10 | (s/fdef collapse-me :args (s/cat :args (s/* int?)) :ret nil?) 11 | (s/fdef function :args (s/cat :i int? :f int? :j (s/* int?)) :ret int?) 12 | ;; End: Generated by clojure.core.typed - DO NOT EDIT 13 | 14 | (defn function 15 | ([i f] (function i f 0)) 16 | ([i j & [k]] 17 | i)) 18 | 19 | 20 | (function 1 2) 21 | (function 1 2 3) 22 | 23 | (defn collapse-me 24 | ([& args])) 25 | 26 | 27 | (collapse-me 1 2) 28 | (collapse-me 1 2 3) 29 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/indirect_ann.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^:skip-wiki clojure.core.typed.checker.indirect-ann 10 | (:require [clojure.core.typed :as t] 11 | [clojure.core.typed.checker.type-rep :as r] 12 | clojure.core.typed.checker.indirect-ops)) 13 | 14 | (t/ann clojure.core.typed.checker.indirect-ops/unparse-type [r/Type -> t/Any]) 15 | -------------------------------------------------------------------------------- /script/deps/projects-that-use: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Prints the subprojects in `projects` that use the specified project. 4 | 5 | set -e 6 | 7 | PROJECTNAME=$1 8 | PROJECT="" 9 | 10 | while read line 11 | do 12 | THISNAME=`basename $line` 13 | if [ $PROJECTNAME == $THISNAME ] || [ $PROJECTNAME == $line ]; then 14 | PROJECT=$line 15 | fi 16 | done < projects 17 | 18 | if [ -z $PROJECT ]; then 19 | echo "Must specify project" 20 | exit 1 21 | fi 22 | 23 | #echo "Finding who uses $PROJECT" 24 | 25 | check_downstream() { 26 | NAME=`basename $1` 27 | cd $NAME 28 | # allow grep to return an error 29 | USESVERSION=$(clj -Stree | grep "$PROJECT" || true) 30 | if [[ $USESVERSION != "" ]]; then 31 | echo $NAME depends on $USESVERSION 32 | fi 33 | cd .. 34 | } 35 | 36 | export -f check_downstream 37 | export PROJECT 38 | cat projects | parallel check_downstream {} 39 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/cast.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.cast 2 | (:refer-clojure :exclude [update cast]) 3 | (:require 4 | [clojure.core.typed.test.test-utils :refer :all] 5 | [clojure.test :refer :all] 6 | [clojure.core.typed :as tc :refer [Int cast]] 7 | )) 8 | 9 | (deftest typed-cast-test 10 | (is-tc-e (cast Int 1) Int) 11 | (is-tc-err #(cast Int (inc 'a))) 12 | (is-tc-e (cast [Int -> Int] identity) [Int -> Int]) 13 | (is-tc-e (cast '{:a Int} {:a 1}) '{:a Int}) 14 | (is-tc-e #(cast Int nil) [:-> Int]) 15 | ;; runtime errors 16 | (is (thrown? Exception (tc/check-form-info `(tc/cast tc/Int nil)))) 17 | (is (thrown? Exception 18 | (tc-e (cast '{:a Int} {:a nil})))) 19 | (is (thrown? Exception 20 | (tc-e 21 | ((:a (cast '{:a [Int :-> Int]} {:a str})) 22 | 1)))) 23 | ) 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/coerce_ann.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^:skip-wiki clojure.core.typed.checker.coerce-ann 10 | (:require [clojure.core.typed :as t] 11 | clojure.core.typed.coerce-utils)) 12 | 13 | (t/ann ^:no-check clojure.core.typed.coerce-utils/Class->symbol [Class -> t/Sym]) 14 | (t/ann ^:no-check clojure.core.typed.coerce-utils/symbol->Class [t/Sym -> Class]) 15 | -------------------------------------------------------------------------------- /typed/annotator.jvm/test/clojure/core/typed/annotator/test/runtime_infer/def_name.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.annotator.test.runtime-infer.def-name 2 | {:lang :core.typed 3 | :core.typed {:features #{:runtime-infer}} 4 | } 5 | (:require [clojure.core.typed :as t] 6 | [clojure.pprint :refer [pprint]])) 7 | 8 | (defn game-over-success [game-state] 9 | (reset! game-state {:sector [1 2] 10 | :quadrant [3 2] 11 | :energy 33 12 | :is_docked false 13 | :shields 343}) 14 | (reset! game-state {:extra 1 15 | :sector [1 2] 16 | :quadrant [3 2] 17 | :energy 33 18 | :is_docked false 19 | :shields 343}) 20 | (swap! game-state assoc :is_docked true) 21 | nil) 22 | 23 | (game-over-success (atom {})) 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/check/local.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.check.local 10 | (:require [clojure.core.typed.checker.local-result :as local-result] 11 | [clojure.core.typed.checker.utils :as u])) 12 | 13 | (defn check-local [{sym :name :as expr} expected] 14 | (assoc expr 15 | u/expr-type (local-result/local-result expr sym expected))) 16 | -------------------------------------------------------------------------------- /script/rename-namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | OLD_NAMESPACE=$1 6 | NEW_NAMESPACE=$2 7 | 8 | if [ -z $OLD_NAMESPACE ]; then 9 | echo "Must provide old namespace" 10 | exit 1 11 | fi 12 | 13 | if [ -z $NEW_NAMESPACE ]; then 14 | echo "Must provide old namespace" 15 | exit 1 16 | fi 17 | 18 | # 1. namespaced keywords/symbols 19 | # 2. ending in space 20 | # 3. ending in newline 21 | # 4. ending in paren 22 | # 5. ending in square bracket 23 | git grep -l $OLD_NAMESPACE | xargs sed -i '' "s/${OLD_NAMESPACE}\//${NEW_NAMESPACE}\//g" 24 | git grep -l $OLD_NAMESPACE | xargs sed -i '' "s/${OLD_NAMESPACE} /${NEW_NAMESPACE} /g" 25 | git grep -l $OLD_NAMESPACE | xargs sed -i '' "s/${OLD_NAMESPACE}\$/${NEW_NAMESPACE}/g" 26 | git grep -l $OLD_NAMESPACE | xargs sed -i '' "s/${OLD_NAMESPACE})/${NEW_NAMESPACE})/g" 27 | git grep -l $OLD_NAMESPACE | xargs sed -i '' "s/${OLD_NAMESPACE}]/${NEW_NAMESPACE}]/g" 28 | -------------------------------------------------------------------------------- /script/git/clone-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | clone () { 6 | GROUPID=`dirname $1` 7 | ARTIFACTID=`basename $1` 8 | if [ "$GITHUB_ACTIONS" = true ]; then 9 | # don't need push access, clone with HTTPS 10 | git clone https://github.com/typedclojure/$ARTIFACTID.git --origin typedclojure 11 | else 12 | git clone git@github.com:typedclojure/$ARTIFACTID.git --origin typedclojure 13 | fi 14 | cd $ARTIFACTID 15 | git branch --set-upstream-to typedclojure/master 16 | if [ "$GROUPID" == "org.clojure" ]; then 17 | git remote add clojure git@github.com:clojure/$ARTIFACTID.git 18 | fi 19 | cd .. 20 | } 21 | 22 | # https://stackoverflow.com/a/26759734 23 | if [ -x "$(command -v parallel)" ]; then 24 | export -f clone 25 | cat projects | parallel clone {} 26 | else 27 | # https://stackoverflow.com/a/1521498 28 | while read p; do 29 | clone "$p" 30 | done Any]) 12 | (defn ^:skip-wiki ignore-with-unchecked-cast* [form ty] 13 | form) 14 | 15 | (defmacro ignore-with-unchecked-cast 16 | "Assumes the form is well typed and annotates it with the provided 17 | type without verifying." 18 | [form ty] 19 | `(ignore-with-unchecked-cast* ~form '~ty)) 20 | -------------------------------------------------------------------------------- /typed/analyzer.common/src/clojure/core/typed/analyzer/common/passes/cleanup.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Nicola Mometto, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | ;copied from clojure.tools.analyzer.passes.cleanup 10 | (ns clojure.core.typed.analyzer.common.passes.cleanup) 11 | 12 | (defn cleanup 13 | {:pass-info {:walk :any :depends #{}}} 14 | [ast] 15 | (-> ast 16 | (update-in [:env] dissoc :loop-locals-casts) 17 | (update-in [:env :locals] #(reduce-kv (fn [m k l] (assoc m k (dissoc l :env :init))) {} %)) 18 | (dissoc :atom))) 19 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/rec_protocol.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.rec-protocol 2 | (:require [clojure.core.typed :as t :refer [ann-protocol ann-datatype check-ns]])) 3 | 4 | (t/defprotocol SelfProtocol 5 | (f1 [this] :- (U nil SelfProtocol))) 6 | 7 | ;(declare-protocol 8 | ; [[f :variance :covariant]] 9 | ; HOProtocol1) 10 | ; 11 | ;Foo <: (HOProtocol2 Foo) 12 | ;Foo <: (HOProtocol2 Foo) 13 | 14 | (ann-protocol [[f :variance :covariant 15 | :< (HOProtocol2 f)]] 16 | HOProtocol2) 17 | ;my-method 18 | ; [(HOProtocol2 Id) -> 19 | ; (U (HOProtocol1 (TFn [[x :variance :covariant]] 20 | ; Integer)) 21 | ; (HOProtocol1 (TFn [[x :variance :covariant]] 22 | ; Number)))]) 23 | 24 | (ann-protocol [[f :variance :covariant 25 | :< (HOProtocol1 Any)]] 26 | HOProtocol1) 27 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP_83_performance.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP-83-performance 2 | (:require 3 | [clojure.core.typed :as t])) 4 | 5 | (defmacro pf [frm] 6 | frm 7 | #_`(t/print-filterset ~(str frm) ~frm)) 8 | 9 | (t/defalias VersionVector (t/NonEmptyVec Number)) 10 | (t/ann version-less [(t/U nil VersionVector) (t/U nil VersionVector) -> t/Any]) 11 | (defn version-less 12 | "Compare two version vectors." 13 | [v1 v2] 14 | (t/loop [v1 :- (t/NilableNonEmptySeq t/Num) (seq v1) 15 | v2 :- (t/NilableNonEmptySeq t/Num) (seq v2)] 16 | (let [fv1 (first v1) 17 | fv2 (first v2)] 18 | (cond 19 | (pf (and (pf (not v1)) 20 | (pf (not v2)))) false 21 | (and v1 (not v2)) false 22 | (or (and (not v1) v2) 23 | (and fv1 fv2 (< fv1 fv2))) 24 | true 25 | (and fv1 fv2 (> fv1 fv2)) false 26 | :else (recur (next v1) (next v2)) 27 | )))) 28 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/recursive.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.recursive 2 | (:require [clojure.core.typed :as t :refer [ann-record ann-protocol]]) 3 | (:import [clojure.lang ISeq])) 4 | 5 | (t/declare-protocols IValidator) 6 | 7 | (ann-record ValidationError [validator :- IValidator 8 | value :- t/Any]) 9 | 10 | (t/tc-ignore 11 | (defrecord ValidationError [validator value]) 12 | ) 13 | 14 | (ann-record ValidationResult 15 | [status :- (t/U ':ok ':error) 16 | result :- t/Any 17 | errors :- (t/U nil (t/Seq ValidationError)) 18 | input :- t/Any]) 19 | 20 | (t/tc-ignore 21 | (defrecord ValidationResult [status result errors input]) 22 | ) 23 | 24 | (t/defprotocol IValidator 25 | "Validator abstraction" 26 | (validate- [this value] :- ValidationResult 27 | "Evaluates the validator.")) 28 | 29 | (t/ann-form validate- [IValidator t/Any -> ValidationResult]) 30 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/defprotocol.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.defprotocol 2 | (:refer-clojure :exclude [defprotocol fn]) 3 | (:require [clojure.core.typed :as t :refer [defprotocol fn]])) 4 | 5 | (defprotocol Foo 6 | (is-foo [this, a :- t/Num] :- t/Num) 7 | (is-bar [this, a :- t/Int] :- t/Int 8 | [this, b :- t/Num] :- t/Num) 9 | (is-baz [this, a :- t/Int] :- t/Int 10 | [this, a :- t/Int, b :- t/Int] :- t/Int 11 | [this, a :- t/Int, b :- t/Int, c :- t/Int] :- t/Int)) 12 | 13 | (defprotocol DocD 14 | "This is a docstring" 15 | (docd [this, a :- t/Num] :- t/Num 16 | "trailing docstring")) 17 | 18 | (fn [a :- Foo] 19 | (is-foo a 1)) 20 | 21 | (fn [a :- Foo] :- t/Int 22 | (is-bar a 1)) 23 | 24 | (fn [a :- Foo] :- t/Num 25 | (is-bar a 1.1)) 26 | 27 | (fn [a :- Foo] :- t/Int 28 | (is-baz a 1)) 29 | 30 | (fn [a :- Foo] :- t/Int 31 | (is-baz a 1 1)) 32 | 33 | (fn [a :- Foo] :- t/Int 34 | (is-baz a 1 1 1)) 35 | -------------------------------------------------------------------------------- /typed/runtime.jvm/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | runtime.jvm 5 | An optional type system for Clojure — zero-dependency artifact for annotations only. 6 | typed.runtime.jvm 7 | 1.0.2-SNAPSHOT 8 | 9 | 10 | 11 | Eclipse Public License 1.0 12 | http://opensource.org/licenses/eclipse-1.0.php 13 | repo 14 | 15 | 16 | 17 | 18 | org.clojure.typed 19 | pom 20 | 1.0.2-SNAPSHOT 21 | ../.. 22 | 23 | 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/check/binding.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.check.binding 10 | (:require [clojure.core.typed.util-vars :as vs] 11 | [clojure.core.typed.checker.utils :as u])) 12 | 13 | (defn check-binding 14 | [check {:keys [init] :as expr} expected] 15 | (let [cinit (binding [vs/*current-expr* init] 16 | (check init expected))] 17 | (assoc expr 18 | :init cinit 19 | u/expr-type (u/expr-type cinit)))) 20 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/check/quote.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.check.quote 10 | (:require [clojure.core.typed.checker.utils :as u] 11 | [clojure.core.typed.checker.check.const :as const])) 12 | 13 | (defn check-quote [check constant-type {:keys [expr] :as quote-expr} expected] 14 | (let [cexpr (const/check-const constant-type true expr expected)] 15 | (assoc quote-expr 16 | :expr cexpr 17 | u/expr-type (u/expr-type cexpr)))) 18 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/check/multi_utils.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.check.multi-utils 10 | (:require [clojure.core.typed.contract-utils :as con] 11 | [clojure.core.typed.checker.type-rep :as r])) 12 | 13 | (defonce ^:dynamic *current-mm* nil) 14 | (set-validator! #'*current-mm* (some-fn nil? 15 | (con/hmap-c? :dispatch-fn-type r/Type? 16 | :dispatch-val-ret r/TCResult?))) 17 | -------------------------------------------------------------------------------- /typed/annotator.jvm/test/clojure/core/typed/annotator/test/spec_infer.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.annotator.test.spec-infer 2 | {:lang :core.typed 3 | :core.typed {:features #{:runtime-infer}} 4 | } 5 | (:refer-clojure :exclude [alias]) 6 | (:require [clojure.core.typed :as t])) 7 | 8 | ;; Start: Generated by clojure.core.typed - DO NOT EDIT 9 | (declare alias alias__347185) 10 | (t/defalias alias (t/U t/Sym Long)) 11 | (t/defalias alias__347185 (t/U t/Str Long)) 12 | (t/ann 13 | mapfn 14 | [[alias :-> alias__347185] 15 | (t/U (t/Seqable (t/U t/Sym Long)) (t/Seqable t/Sym) (t/Vec Long)) 16 | :-> 17 | (t/Seqable (t/U t/Str Long))]) 18 | ;; End: Generated by clojure.core.typed - DO NOT EDIT 19 | 20 | (do 21 | (defn mapfn [f c] 22 | (map f c)) 23 | 24 | (mapfn inc [1 2 3]) 25 | (mapfn inc '(1 2 3)) 26 | (mapfn str '(a b c)) 27 | ) 28 | 29 | #_ 30 | (do 31 | (defn sym 32 | ([name] (symbol name)) 33 | ([ns name] (symbol ns name))) 34 | 35 | (sym "a") 36 | (sym 'a) 37 | (sym "abc" "bcd") 38 | (sym nil "bcd") 39 | ) 40 | -------------------------------------------------------------------------------- /typed/annotator.jvm/test/clojure/core/typed/annotator/test/rt_infer/anon_lambda.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.annotator.test.rt-infer.anon-lambda 2 | {:lang :core.typed 3 | :core.typed {:features #{:runtime-infer}}} 4 | (:require [clojure.core.typed :as t])) 5 | 6 | ;; Start: Generated by clojure.core.typed - DO NOT EDIT 7 | (declare) 8 | (t/ann b [(t/Vec Long) :-> (t/Coll Long)]) 9 | (t/ann c [Long :-> Long]) 10 | (t/ann d [Long :-> Long]) 11 | ;; End: Generated by clojure.core.typed - DO NOT EDIT 12 | (defmacro hidden-f [& args] 13 | `(fn ~@args)) 14 | 15 | (defn b [coll] 16 | (->> coll 17 | (map 18 | (t/ann-form 19 | (fn [n] (inc n)) 20 | [Long :-> Long]) 21 | ) ;; hello 22 | (filter 23 | (t/ann-form 24 | (fn [n] (odd? n)) 25 | [Long :-> (t/U Boolean false)]) 26 | ))) 27 | 28 | (b [1 2 3 4 5]) 29 | 30 | ;(defn c [n] 31 | ; ((hidden-f [a] (inc a)) 32 | ; n)) 33 | ; 34 | ;(c 1) 35 | 36 | (defn d [n] 37 | (#(inc ^{::t/ann Long} %) n)) 38 | 39 | (d 1) 40 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/tap.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.tap 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all] 5 | [clojure.core.typed.test.destructure])) 6 | 7 | (deftest print-tap-diagnostic-test 8 | (is-tc-e #(print-tap-diagnostic "abc") [-> Any] 9 | :requires [[clojure.test.tap :refer [print-tap-diagnostic]]]) 10 | (is-tc-err #(print-tap-diagnostic 1) [-> Any] 11 | :requires [[clojure.test.tap :refer [print-tap-diagnostic]]])) 12 | 13 | (deftest print-tap-plan-test 14 | (is-tc-e #(print-tap-plan 1) [-> Any] 15 | :requires [[clojure.test.tap :refer [print-tap-plan]]])) 16 | 17 | (deftest print-tap-pass-test 18 | (is-tc-e #(print-tap-pass 1) [-> Any] 19 | :requires [[clojure.test.tap :refer [print-tap-pass]]])) 20 | 21 | (deftest print-tap-fail-test 22 | (is-tc-e #(print-tap-fail 1) [-> Any] 23 | :requires [[clojure.test.tap :refer [print-tap-fail]]])) 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/records.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.records 2 | (:require [clojure.core.typed :refer [check-ns ann-record ann-form cf]] 3 | [clojure.repl :refer [pst]])) 4 | 5 | (set! *warn-on-reflection* true) 6 | 7 | (ann-record MyRecord [a :- Number]) 8 | 9 | (defrecord MyRecord [a] 10 | Object 11 | (toString [this] nil)) 12 | 13 | (ann-form (:a (->MyRecord 1)) Number) 14 | (ann-form (map->MyRecord {:a 2}) MyRecord) 15 | 16 | (ann-form (let [^MyRecord r (MyRecord. 1)] 17 | (.a r)) 18 | Number) 19 | 20 | (let [^MyRecord r (MyRecord. 1)] 21 | (ann-form (.a r) Number)) 22 | 23 | (let [r (MyRecord. 1)] 24 | (ann-form (.a r) Number)) 25 | 26 | (ann-form (assoc (->MyRecord 1) :a 1) 27 | MyRecord) 28 | 29 | #_(ann-form (assoc (->MyRecord 1) :a 'a) MyRecord) 30 | 31 | #_(do 32 | (defrecord A [a] 33 | clojure.lang.IFn 34 | (invoke [this query] (get this query))) 35 | (ann-record A [a :- Number])) 36 | 37 | (ann-record [[a :variance :covariant]] 38 | MyPolyRecord [a :- Number]) 39 | -------------------------------------------------------------------------------- /typed/checker.js/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | checker.js 5 | typed.checker.js 6 | An optional type system for ClojureScript — full system for annotating and type-checking. 7 | 1.0.2-SNAPSHOT 8 | 9 | 10 | org.clojure.typed 11 | pom 12 | 1.0.2-SNAPSHOT 13 | ../.. 14 | 15 | 16 | 17 | 18 | org.clojure.typed 19 | checker.jvm 20 | 21 | 22 | org.clojure 23 | clojurescript 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/jvm/reset_caches.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^:skip-wiki clojure.core.typed.checker.jvm.reset-caches 10 | (:require [clojure.core.typed.checker.jvm.subtype :as sub] 11 | [clojure.core.typed.checker.type-ctors :as c] 12 | [clojure.core.typed.checker.cs-gen :as cgen])) 13 | 14 | (defn reset-caches 15 | "Reset internal type caches." 16 | [] 17 | (sub/reset-subtype-cache) 18 | (c/reset-Un-cache) 19 | (c/reset-In-cache) 20 | (c/reset-supers-cache!) 21 | (c/reset-RClass-of-cache!) 22 | (cgen/reset-dotted-var-store!) 23 | nil) 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/CTYP_144.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.CTYP-144 2 | (:require [clojure.core.typed.test.test-utils :refer :all] 3 | [clojure.core.typed.checker.jvm.analyze-clj :as ana] 4 | [clojure.test :refer :all])) 5 | 6 | (deftest instance-method-test 7 | (is-tc-e 8 | (do (defprotocol IRandom 9 | (-next-int 10 | [this limit :- Integer] :- Integer)) 11 | 12 | (ann-record SeededRandom [seed :- Int 13 | rng :- java.util.Random]) 14 | 15 | (defrecord SeededRandom [seed ^java.util.Random rng] 16 | IRandom 17 | (-next-int 18 | [this limit] 19 | (ann-form limit Integer)))))) 20 | 21 | #_(defprotocol IRandom 22 | (-next-int [this limit])) 23 | 24 | #_(-> 25 | (ana/ast-for-form 26 | '(defrecord SeededRandom [seed ^java.util.Random rng] 27 | IRandom 28 | (-next-int [this limit]))) 29 | :body 30 | :statements 31 | (nth 2) 32 | :methods 33 | (nth 29) 34 | :methods 35 | first 36 | keys 37 | ) 38 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/assoc.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.assoc 2 | (:require 3 | [clojure.core.typed.test.test-utils :refer :all] 4 | [clojure.core.typed :refer [ann-form check-ns] :as t] 5 | [clojure.test :refer :all]) 6 | (:import (clojure.lang Symbol))) 7 | 8 | (deftest assoc-test 9 | (is-tc-e (assoc {:a 1} :b 2) 10 | '{:a Number :b Number}) 11 | 12 | (is-tc-err #(let [a 1] 13 | (assoc a :b 2))) 14 | (is-tc-err 15 | (do (t/ann-record FooRec [a :- t/Num 16 | b :- t/Symbol]) 17 | (defrecord FooRec [a b]) 18 | (assoc (->FooRec 1 'a) :a 'b))) 19 | 20 | (is-tc-e 21 | (do (t/ann-record FooRec [a :- t/Num 22 | b :- t/Symbol]) 23 | (defrecord FooRec [a b]) 24 | (assoc (->FooRec 1 'a) :a 4))) 25 | 26 | ;intersections 27 | (is-tc-e (t/fn [m :- (t/I (t/HMap :mandatory {:foo Num}) 28 | (t/HMap :mandatory {:bar Num}))] 29 | :- '{:foo Num, :bar Num, :baz Num} 30 | (assoc m :baz 2)))) 31 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/set_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.set-test 2 | (:require [clojure.core.typed.test.test-utils :refer :all] 3 | [clojure.test :refer :all])) 4 | 5 | (deftest construct-hset 6 | (is-tc-e #{1 2 3} 7 | :expected 8 | (HSet #{1 2 3})) 9 | (is-tc-e #{1 nil} 10 | :expected 11 | (HSet #{nil 1}))) 12 | 13 | (deftest upcast-hset 14 | (is-tc-e #{1 2 3} 15 | :expected 16 | (Set Num)) 17 | (is-tc-e (conj #{1 2 3} 1) 18 | :expected 19 | (Set Num))) 20 | 21 | (deftest set-pred-test 22 | (is-tc-e (let [foo :- (U false nil ':a ':b), :a] 23 | (if (#{:a :b false nil} foo) 24 | (ann-form foo (U ':a ':b)) 25 | (ann-form foo (U false nil))))) 26 | (is-tc-e (let [foo :- (U false nil ':a ':b), :a] 27 | (when (#{:a :b nil} foo) 28 | (ann-form foo (U ':a ':b))))) 29 | (is-tc-e (let [foo :- (U nil ':a ':b), :a] 30 | (when (#{:a :b nil} foo) 31 | (ann-form foo (U ':a ':b)))))) 32 | -------------------------------------------------------------------------------- /typed/analyzer.common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | analyzer.common 5 | A variant of tools.analyzer. 6 | typed.analyzer.common 7 | 1.0.2-SNAPSHOT 8 | 9 | 10 | 11 | Eclipse Public License 1.0 12 | https://opensource.org/licenses/eclipse-1.0.php 13 | repo 14 | 15 | 16 | 17 | 18 | org.clojure.typed 19 | pom 20 | 1.0.2-SNAPSHOT 21 | ../.. 22 | 23 | 24 | 25 | 26 | org.clojure 27 | clojure 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /typed/analyzer.jvm/src/clojure/core/typed/analyzer/jvm/passes/fix_case_test.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Nicola Mometto, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | ;copied from clojure.tools.analyzer.passes.jvm.fix-case-test 10 | (ns clojure.core.typed.analyzer.jvm.passes.fix-case-test 11 | (:require [clojure.core.typed.analyzer.common.passes.add-binding-atom :as add-binding-atom])) 12 | 13 | (defn fix-case-test 14 | "If the node is a :case-test, annotates in the atom shared 15 | by the binding and the local node with :case-test" 16 | {:pass-info {:walk :pre :depends #{#'add-binding-atom/add-binding-atom}}} 17 | [ast] 18 | (when (:case-test ast) 19 | (swap! (:atom ast) assoc :case-test true)) 20 | ast) 21 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/indirect_ops.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.indirect-ops 10 | (:require [clojure.core.typed.checker.indirect-utils :as in])) 11 | 12 | (in/make-indirection unparse-type 13 | parse-type 14 | check-funapp 15 | assoc-pairs-noret 16 | subtype? 17 | -FS 18 | -top-fn 19 | -empty-fn 20 | infer 21 | PropEnv? 22 | -or 23 | -and 24 | type-of-nofail) 25 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/atom.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.atom 2 | (:require [clojure.core.typed :as t :refer [ann ann-form check-ns cf defalias]] 3 | [clojure.repl :refer [pst]]) 4 | (:import (clojure.lang IPersistentMap Symbol))) 5 | 6 | (ann my-atom (t/Atom1 Number)) 7 | (def my-atom (atom 2)) 8 | 9 | (reset! my-atom 1) 10 | (swap! my-atom (t/fn [x :- Number] (+ x 2 3))) 11 | 12 | (defalias InnerEntry '{:c '{:d String}}) 13 | (defalias Entry '{:a '{:b (IPersistentMap Symbol (t/Atom1 InnerEntry))}}) 14 | 15 | (ann complicated (t/Atom1 Entry)) 16 | (def complicated (atom {:a {:b {}}})) 17 | 18 | ;(swap! complicated update-in [:a :b 'a] #(swap! (or % (atom {})) assoc-in [:c :d] "b")) 19 | 20 | (swap! complicated (ann-form 21 | (fn [c] 22 | (-> c 23 | (update-in [:a :b 'a] 24 | (fn [a] (swap! (or a (atom {})) 25 | (fn [i] 26 | (-> i (assoc-in [:c :d] "b")))))))) 27 | [Entry -> Entry])) 28 | -------------------------------------------------------------------------------- /typed/analyzer.jvm/deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["src"] 2 | :deps {org.clojure/clojure {:mvn/version "1.10.1"} 3 | org.clojure/core.memoize {:mvn/version "0.8.2"} 4 | org.ow2.asm/asm {:mvn/version "5.2"} 5 | org.clojure.typed/analyzer.common {:local/root "../analyzer.common" 6 | :deps/manifest :deps}} 7 | :mvn/repos 8 | {"sonatype-oss-public" 9 | {:url "https://oss.sonatype.org/content/groups/public/"}}, 10 | :aliases {:nREPL 11 | {:extra-deps 12 | {nrepl/nrepl {:mvn/version "0.6.0"} 13 | cider/piggieback {:mvn/version "0.3.8"}} 14 | :main-opts ["-m" "nrepl.cmdline" 15 | "--interactive"]} 16 | :test 17 | {:extra-paths ["test"]} 18 | :runner 19 | {:extra-deps {com.cognitect/test-runner 20 | {:git/url "https://github.com/cognitect-labs/test-runner" 21 | :sha "3cb0a9daf1cb746259dc8309b218f9211ad3b33b"}} 22 | :main-opts ["-m" "cognitect.test-runner" 23 | "-r" ".*" 24 | "-d" "test"]}}} 25 | -------------------------------------------------------------------------------- /typed/checker.jvm/tests.edn: -------------------------------------------------------------------------------- 1 | {:kaocha/tests [{:kaocha.testable/type :kaocha.type/clojure.test 2 | :kaocha.testable/id :unit 3 | :kaocha/ns-patterns ["clojure.core.typed.test.*"] 4 | :kaocha/source-paths [] 5 | :kaocha/test-paths ["test"]}] 6 | :kaocha/fail-fast? true 7 | :kaocha/color? true 8 | ;:kaocha/reporter [kaocha.report/dots] 9 | :kaocha/reporter [kaocha.report/dots] 10 | :kaocha/plugins [:kaocha.plugin/randomize 11 | :kaocha.plugin/filter 12 | :kaocha.plugin/capture-output 13 | :kaocha.plugin/profiling 14 | :kaocha.plugin/print-invocations] 15 | ;:kaocha.plugin.randomize/seed 950716166 16 | ;:kaocha.plugin.randomize/randomize? true 17 | ;:kaocha.plugin.profiling/count 3 18 | :kaocha.plugin.profiling/profiling? true} 19 | -------------------------------------------------------------------------------- /typed/lib.clojure/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | lib.clojure 5 | Type annotations and macros for the base Clojure distribution. 6 | typed.lib.clojure 7 | 1.0.2-SNAPSHOT 8 | 9 | 10 | 11 | Eclipse Public License 1.0 12 | http://opensource.org/licenses/eclipse-1.0.php 13 | repo 14 | 15 | 16 | 17 | 18 | org.clojure.typed 19 | pom 20 | 1.0.2-SNAPSHOT 21 | ../.. 22 | 23 | 24 | 25 | 26 | org.clojure.typed 27 | runtime.jvm 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /typed/analyzer.js/deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["src"] 2 | :deps {org.clojure/clojure {:mvn/version "1.10.1"} 3 | org.clojure/tools.analyzer {:mvn/version "1.0.0"} 4 | org.clojure/clojurescript {:mvn/version "1.10.597"} 5 | org.clojure.typed/analyzer.common {:local/root "../analyzer.common" 6 | :deps/manifest :deps}} 7 | :mvn/repos 8 | {"sonatype-oss-public" 9 | {:url "https://oss.sonatype.org/content/groups/public/"}}, 10 | :aliases {:nREPL 11 | {:extra-deps 12 | {nrepl/nrepl {:mvn/version "0.6.0"} 13 | cider/piggieback {:mvn/version "0.3.8"}} 14 | :main-opts ["-m" "nrepl.cmdline" 15 | "--interactive"]} 16 | :test 17 | {:extra-paths ["test"]} 18 | :runner 19 | {:extra-deps {com.cognitect/test-runner 20 | {:git/url "https://github.com/cognitect-labs/test-runner" 21 | :sha "3cb0a9daf1cb746259dc8309b218f9211ad3b33b"}} 22 | :main-opts ["-m" "cognitect.test-runner" 23 | "-r" ".*" 24 | "-d" "test"]}}} 25 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ring.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ring 2 | (:require [clojure.core.typed :refer [ann check-ns ann-form print-env cf]]) 3 | (:import (clojure.lang IPersistentMap IPersistentVector))) 4 | 5 | (comment 6 | (ann assoc-conj 7 | (All [x] (Fn [(IPersistentMap Any (U x (IPersistentVector x))) Any x -> 8 | (IPersistentMap Any (U x (IPersistentVector x)))] 9 | [(IPersistentVector (U x (IPersistentVector x))) Integer x -> 10 | (IPersistentVector (U x (IPersistentVector x)))]))) 11 | (defn assoc-conj 12 | "Associate a key with a value in a map. If the key already exists in the map, 13 | a vector of values is associated with the key." 14 | [map key val] 15 | (ann-form map (IPersistentMap Any (U x (IPersistentVector x)))) 16 | (print-env "top") 17 | (assoc map key 18 | (if-let [cur (get map key)] 19 | (do 20 | (print-env "map") 21 | (if (vector? cur) 22 | (do (print-env "cur") 23 | (conj cur val)) 24 | [cur val]) 25 | ) 26 | val))) 27 | 28 | (check-ns) 29 | ) 30 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/poly_record.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.poly-record 2 | (:require [clojure.core.typed :as t])) 3 | 4 | (t/ann-record [[foo :variance :invariant]] Foo [b :- (t/U nil Number)]) 5 | (t/tc-ignore 6 | (defrecord Foo [b]) 7 | ) 8 | 9 | (comment 10 | (defmacro defrecord> 11 | "Define a typed record. 12 | 13 | eg. ;monomorphic 14 | (defrecord> FooM [a :- (U nil Number), 15 | b :- Number] 16 | Object 17 | (toString [this] \"\")) 18 | 19 | ;polymorphic 20 | (defrecord> [[x :variance :covariant]] 21 | FooP [a :- x, 22 | b :- Number] 23 | Object 24 | (toString [this] \"\"))" 25 | [& args] 26 | (let [vbnd (when (vector? (first args)) 27 | (first args)) 28 | args (if vbnd 29 | (next args) 30 | args) 31 | [nme fields & args] args] 32 | `(do (ann-record 33 | ~@(concat (when vbnd 34 | [vbnd]) 35 | nme 36 | fields)) 37 | (defrecord ~nme ~(mapv first (partition 3 fields)) 38 | ~@args)))) 39 | ) 40 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/pomegranate.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.pomegranate 2 | (:import (clojure.lang Named)) 3 | (:require [clojure.core.typed :as t])) 4 | 5 | #_(t/non-nil-return java.lang.Class/getDeclaredMethod :all) 6 | #_(t/nilable-param java.lang.reflect.Method/invoke {2 #{0}}) 7 | 8 | (t/ann call-method [Class Named (t/Vec Class) (t/U nil Object) (t/U nil Object) * -> (t/U nil Object)]) 9 | 10 | ;; call-method pulled from clojure.contrib.reflect, (c) 2010 Stuart Halloway & Contributors 11 | (defn call-method 12 | "Calls a private or protected method. 13 | 14 | params is a vector of classes which correspond to the arguments to 15 | the method e 16 | 17 | obj is nil for static methods, the instance object otherwise. 18 | 19 | The method-name is given a symbol or a keyword (something Named)." 20 | [^Class klass method-name params obj & args] 21 | (let [method (doto (.getDeclaredMethod klass 22 | (name method-name) 23 | (t/into-array> Class params)) 24 | (.setAccessible true))] 25 | (.invoke method obj (t/into-array> (t/U nil Object) args)))) 26 | -------------------------------------------------------------------------------- /typed/runtime.jvm/deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["src"] 2 | :deps {org.clojure/clojure {:mvn/version "1.10.1"}} 3 | :aliases {:test 4 | {:extra-paths ["test"] 5 | :extra-deps {org.clojure/clojurescript {:mvn/version "1.10.597"}}} 6 | :nREPL 7 | {:extra-deps 8 | {nrepl/nrepl {:mvn/version "0.6.0"} 9 | cider/cider-nrepl {:mvn/version "0.22.4"}}, 10 | :main-opts ["-m" "nrepl.cmdline" 11 | "--interactive" 12 | "--middleware" "[\"cider.nrepl/cider-middleware\"]" 13 | ]} 14 | 15 | :codox 16 | {:extra-deps {codox/codox {:mvn/version "0.10.5"}} 17 | :extra-paths ["script"] 18 | :main-opts ["-m" "gen-doc"]} 19 | 20 | :runner 21 | {:extra-deps {com.cognitect/test-runner 22 | {:git/url "https://github.com/cognitect-labs/test-runner" 23 | :sha "3cb0a9daf1cb746259dc8309b218f9211ad3b33b"}} 24 | :main-opts ["-m" "cognitect.test-runner" 25 | "-d" "test" 26 | "-r" ".*" 27 | ]}}} 28 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/contract_ann.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.contract-ann 10 | (:require [clojure.core.typed :as t])) 11 | 12 | (t/ann ^:no-check clojure.core.typed.contract-utils/nat? [t/Any * -> Boolean]) 13 | (t/ann ^:no-check clojure.core.typed.contract-utils/hash-c? [[t/Any -> t/Any] [t/Any -> t/Any] -> [t/Any -> t/Any]]) 14 | ;can't express alternating args 15 | (t/ann ^:no-check clojure.core.typed.contract-utils/hmap-c? [t/Any * -> [t/Any -> t/Any]]) 16 | (t/ann ^:no-check clojure.core.typed.contract-utils/set-c? [[t/Any -> t/Any] -> [t/Any -> t/Any]]) 17 | (t/ann ^:no-check clojure.core.typed.contract-utils/every-c? [[t/Any -> t/Any] -> [(t/U nil (t/Seqable t/Any)) -> t/Any]]) 18 | -------------------------------------------------------------------------------- /typed/annotator.jvm/test/clojure/core/typed/annotator/test/runtime_infer/gen_arglists.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.annotator.test.runtime-infer.gen-arglists 2 | {:lang :core.typed 3 | :core.typed {:features #{:runtime-infer}} 4 | } 5 | (:refer-clojure :exclude [*]) 6 | (:require [clojure.core.typed :as t] 7 | [clojure.core :as core] 8 | [clojure.spec.alpha :as s] 9 | [clojure.pprint :refer [pprint]])) 10 | 11 | ;; Start: Generated by clojure.core.typed - DO NOT EDIT 12 | (s/fdef * :args (s/cat :x int? :xs-0 int?) :ret int?) 13 | (s/fdef 14 | function 15 | :args 16 | (s/alt :1-arg (s/cat :a int?) :2-args (s/cat :a int? :b-0 int?)) 17 | :ret 18 | int?) 19 | (s/fdef 20 | function2 21 | :args 22 | (s/alt :1-arg (s/cat :a int?) :2-args (s/cat :a int? :b-0 int?)) 23 | :ret 24 | int?) 25 | ;; End: Generated by clojure.core.typed - DO NOT EDIT 26 | (def function 27 | (fn 28 | ([a] a) 29 | ([a & b] a))) 30 | 31 | (def * 32 | (fn 33 | ([] 1) 34 | ([x] x) 35 | ([x & xs] 36 | (reduce (fnil core/* 0M 0M) x xs)))) 37 | 38 | (def function2 function) 39 | 40 | (function 1) 41 | (function 1 2) 42 | 43 | (function2 1 2) 44 | (function2 1) 45 | 46 | (* 2 3) 47 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/jvm/reflect_utils.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^:skip-wiki clojure.core.typed.checker.jvm.reflect-utils 10 | (:require [clojure.reflect :as reflect] 11 | [clojure.string :as str]) 12 | (:import (clojure.lang RT))) 13 | 14 | (defn reflect 15 | [obj & options] 16 | (apply reflect/type-reflect (if (class? obj) obj (class obj)) 17 | :reflector (reflect/->JavaReflector (RT/baseLoader)) 18 | options)) 19 | 20 | (defn reflect-friendly-sym [cls] 21 | (-> (reflect/typename cls) 22 | (str/replace "[]" "<>") 23 | symbol)) 24 | 25 | (defn pprint-reflection-sym [cls] 26 | (-> (reflect/typename cls) 27 | (str/replace "<>" "[]") 28 | symbol)) 29 | -------------------------------------------------------------------------------- /script/bump-readme-version.clj: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env clojure 2 | 3 | (set! *warn-on-reflection* true) 4 | 5 | (require '[clojure.java.io :as io] 6 | '[clojure.string :as str]) 7 | 8 | (def new-version-string (first *command-line-args*)) 9 | (assert (string? new-version-string) 10 | (str "Must pass version string as first argument to program")) 11 | 12 | (defn update-readme-file [readme-file] 13 | (assert (string? readme-file) 14 | (str "Must pass readme file to program")) 15 | (let [original-readme-file-lines (doall (-> readme-file io/reader line-seq)) 16 | version-string 17 | (some (fn [^String line] 18 | (when (.startsWith line "Latest stable release is") 19 | (subs line (count "Latest stable release is ") (dec (count line))))) 20 | original-readme-file-lines) 21 | new-readme-file-lines 22 | (map #(str/replace % version-string new-version-string) 23 | original-readme-file-lines)] 24 | (spit readme-file (str (str/join "\n" new-readme-file-lines) "\n")))) 25 | 26 | (mapv update-readme-file (rest *command-line-args*)) 27 | (apply println (str "Updated to version: " new-version-string ":") 28 | (rest *command-line-args*)) 29 | -------------------------------------------------------------------------------- /typed/analyzer.common/src/clojure/core/typed/analyzer/common/passes/source_info.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Nicola Mometto, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | ;copied from clojure.tools.analyzer.passes.source-info 10 | (ns clojure.core.typed.analyzer.common.passes.source-info 11 | (:require [clojure.core.typed.analyzer.common.utils :refer [-source-info merge']])) 12 | 13 | (defn -merge-source-info [source-info] 14 | (fn [ast] 15 | (update-in ast [:env] merge' source-info))) 16 | 17 | (defn source-info 18 | "Adds (when available) :line, :column, :end-line, :end-column and :file info to the AST :env" 19 | {:pass-info {:walk :pre :depends #{}}} 20 | [ast] 21 | (let [source-info (-source-info (:form ast) (:env ast)) 22 | merge-source-info (-merge-source-info source-info)] 23 | (merge-source-info ast))) 24 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/protocol_untyped_extend.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.protocol-untyped-extend 2 | (:require [clojure.core.typed :refer [ann-protocol tc-ignore 3 | ann-datatype ann check-ns] 4 | :as t] 5 | [clojure.core.typed.test.protocol-in-another-ns 6 | :refer [AnotherNs baz]])) 7 | 8 | (t/defprotocol IFoo 9 | (bar [this])) 10 | 11 | (ann-datatype Bar []) 12 | (deftype Bar []) 13 | 14 | (extend-protocol IFoo 15 | Bar 16 | (bar [b] 'a) 17 | 18 | nil 19 | (bar [c] 'd)) 20 | 21 | (ann takes-IFoo [IFoo -> t/Any]) 22 | (defn takes-IFoo [f] 23 | (bar f)) 24 | 25 | ; don't eval; see CLJ-979 26 | (fn [] (takes-IFoo (->Bar))) 27 | 28 | ;; Annotate protocol in another ns 29 | 30 | (ann-protocol clojure.core.typed.test.protocol-in-another-ns/AnotherNs 31 | baz 32 | [AnotherNs -> t/Any]) 33 | 34 | (extend-protocol AnotherNs 35 | Bar 36 | (baz [this] nil)) 37 | 38 | (ann takes-AnotherNs [AnotherNs -> t/Any]) 39 | (defn takes-AnotherNs [a] 40 | (baz a)) 41 | 42 | ; don't eval; see CLJ-979 43 | (fn [] 44 | (takes-AnotherNs (->Bar))) 45 | 46 | ;; A protocol that extends 47 | 48 | ;(deftype Pair [a] 49 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/nilsafe_utils.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^:skip-wiki clojure.core.typed.checker.nilsafe-utils 10 | (:require [clojure.set :as set] 11 | [clojure.core.typed :as t])) 12 | 13 | (t/ann ^:no-check set-union 14 | (t/All [x] 15 | (t/IFn [-> (t/Set x)] 16 | [(t/U nil (t/Set x)) -> (t/Set x)] 17 | [(t/U nil (t/Set x)) (t/Set x) * -> (t/Set x)]))) 18 | (def set-union (fnil set/union #{})) 19 | 20 | (t/ann ^:no-check set-difference 21 | (t/All [x] 22 | (t/IFn [(t/U nil (t/Set x)) -> (t/Set x)] 23 | [(t/U nil (t/Set x)) (t/Set t/Any) * -> (t/Set x)]))) 24 | (def set-difference (fnil set/difference #{})) 25 | -------------------------------------------------------------------------------- /typed/checker.js/src/clojure/core/typed/check_ns_cljs.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.check-ns-cljs 10 | (:require [cljs.compiler :as comp] 11 | [clojure.core.typed.current-impl :as impl] 12 | [cljs.env :as env] 13 | [clojure.core.typed.util-cljs :as ucljs] 14 | [clojure.core.typed.checker.check-ns-common :as chk-ns])) 15 | 16 | (defn check-ns-info 17 | [ns-or-syms opt] 18 | (ucljs/with-cljs-typed-env 19 | (comp/with-core-cljs 20 | nil 21 | #(chk-ns/check-ns-info impl/clojurescript ns-or-syms opt)))) 22 | 23 | (defn check-ns 24 | [ns-or-syms opt] 25 | (ucljs/with-cljs-typed-env 26 | (comp/with-core-cljs 27 | nil 28 | #(chk-ns/check-ns impl/clojurescript ns-or-syms opt)))) 29 | -------------------------------------------------------------------------------- /typed/lang.jvm/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | lang.jvm 5 | typed.lang.jvm 6 | Extensible languages in Clojure, a la Racket's #lang. 7 | 1.0.2-SNAPSHOT 8 | 9 | 10 | 11 | Eclipse Public License 1.0 12 | http://opensource.org/licenses/eclipse-1.0.php 13 | repo 14 | 15 | 16 | 17 | 18 | org.clojure.typed 19 | pom 20 | 1.0.2-SNAPSHOT 21 | ../.. 22 | 23 | 24 | 25 | 26 | org.clojure 27 | clojure 28 | 29 | 30 | org.clojure 31 | tools.namespace 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /typed/runtime.jvm/src/clojure/core/typed/env.cljc: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.env) 10 | 11 | (def ^:dynamic *checker* nil) 12 | 13 | (defn checker-or-nil [] 14 | {:post [(or #?(:clj (instance? clojure.lang.IAtom %) 15 | :cljs (instance? Atom %)) 16 | (nil? %))]} 17 | *checker*) 18 | 19 | (defn checker [] 20 | (let [c *checker*] 21 | (assert #?(:clj (instance? clojure.lang.IAtom c) 22 | :cljs (instance? Atom c)) 23 | (str "No checker state: " (pr-str c))) 24 | c)) 25 | 26 | (defn empty-checker [] 27 | {}) 28 | 29 | (defn init-checker [] 30 | (atom (empty-checker) 31 | :validator map?)) 32 | 33 | (defn deref-checker [] 34 | {:post [(map? %)]} 35 | @(checker)) 36 | 37 | (defn swap-checker! [& args] 38 | (apply swap! (checker) args)) 39 | -------------------------------------------------------------------------------- /typed/checker.js/src/clojure/core/typed/analyzer_api_intercept.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.analyzer-api-intercept 10 | (:require [cljs.analyzer.api :as api] 11 | [clojure.core.typed.ast-utils :as ast-u])) 12 | 13 | (def ops-found (atom #{})) 14 | 15 | (defn reset-found [] 16 | (reset! ops-found #{})) 17 | 18 | (defn walk-collect-ops [{:keys [op children] :as node}] 19 | (when-not (some (partial = op) @ops-found) 20 | (swap! ops-found #(conj % op))) 21 | (when children 22 | (doseq [c children] 23 | (walk-collect-ops (c node))))) 24 | 25 | (defn analyze 26 | ([env form] (analyze env form nil {})) 27 | ([env form x opts] 28 | (let [result (api/analyze env form x opts)] 29 | (walk-collect-ops result) 30 | ;(println ops-found) 31 | result))) 32 | 33 | (defn empty-env [] 34 | (api/empty-env)) 35 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/jvm/rclass_env.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^:skip-wiki clojure.core.typed.checker.jvm.rclass-env 10 | (:require [clojure.core.typed.contract-utils :as con] 11 | [clojure.core.typed.checker.type-rep :as r])) 12 | 13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 14 | ;; Restricted Class 15 | 16 | ;Class -> RClass 17 | (defonce RESTRICTED-CLASS (atom {})) 18 | (set-validator! RESTRICTED-CLASS (con/hash-c? symbol? r/Type?)) 19 | 20 | (defn get-rclass 21 | "Returns the RClass with class symbol csym. 22 | Returns nil if not found." 23 | [csym] 24 | (@RESTRICTED-CLASS csym)) 25 | 26 | (defn alter-class* [csym type] 27 | (assert (r/Type? type) 28 | (str "alter-class* " csym " not a type: " type)) 29 | (swap! RESTRICTED-CLASS assoc csym type)) 30 | 31 | (defn reset-rclass-env! [m] 32 | (reset! RESTRICTED-CLASS m) 33 | nil) 34 | -------------------------------------------------------------------------------- /typed/analyzer.jvm/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | analyzer.jvm 5 | A variant of tools.analyzer.jvm. 6 | typed.analyzer.jvm 7 | 1.0.2-SNAPSHOT 8 | 9 | 10 | 11 | Eclipse Public License 1.0 12 | https://opensource.org/licenses/eclipse-1.0.php 13 | repo 14 | 15 | 16 | 17 | 18 | org.clojure.typed 19 | pom 20 | 1.0.2-SNAPSHOT 21 | ../.. 22 | 23 | 24 | 25 | 26 | org.clojure.typed 27 | analyzer.common 28 | 29 | 30 | org.clojure 31 | core.memoize 32 | 33 | 34 | org.ow2.asm 35 | asm 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/protocol.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.protocol 2 | (:require [clojure.core.typed :as t :refer [ann-protocol ann-datatype check-ns]])) 3 | 4 | (t/defprotocol AddProtoc 5 | (adder [this amount :- t/Num] :- t/Num)) 6 | 7 | (ann-datatype Accumulator [t :- Number]) 8 | (deftype Accumulator [t] 9 | AddProtoc 10 | (adder [_ i] 1)) 11 | 12 | (ann-protocol short/ShortNs) 13 | 14 | ;; polymorphic protocols 15 | 16 | (t/defprotocol 17 | [[x :variance :covariant]] 18 | IFoo 19 | (bar [this] :- t/Num) 20 | (baz [this] :- t/Any)) 21 | 22 | ;TODO 23 | ;(ann-datatype FooPoly [] 24 | ; :unchecked-ancestors 25 | ; [(IFoo Any)]) 26 | ;(deftype FooPoly [] 27 | ; IFoo 28 | ; (bar [_] 1)) 29 | 30 | ;#(bar (FooPoly.)) 31 | ; 32 | ;;; extend a polymophic protocol after deftype definition 33 | ; 34 | ;(ann-datatype FooLatePoly []) 35 | ;(deftype FooLatePoly []) 36 | ; 37 | ;(extend-type FooLatePoly 38 | ; IFoo 39 | ; (bar [this] 1)) 40 | 41 | ; annotate first position in methods 42 | (t/defalias FunctorLB 43 | (t/TFn [[x :variance :covariant]] 44 | t/Nothing)) 45 | 46 | (t/defprotocol [[F :variance :covariant, 47 | :> FunctorLB 48 | :< Functor]] 49 | Functor 50 | ([a b c ...] fmap [fv :- (F a), g :- [a :-> b]] :- (F b))) 51 | 52 | (comment 53 | (check-ns 'clojure.core.typed.test.protocol) 54 | ) 55 | -------------------------------------------------------------------------------- /typed/lib.core.async/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | lib.core.async 5 | typed.lib.core.async 6 | Type annotations and macros for core.async. 7 | 1.0.2-SNAPSHOT 8 | 9 | 10 | 11 | Eclipse Public License 1.0 12 | http://opensource.org/licenses/eclipse-1.0.php 13 | repo 14 | 15 | 16 | 17 | 18 | org.clojure.typed 19 | pom 20 | 1.0.2-SNAPSHOT 21 | ../.. 22 | 23 | 24 | 25 | 26 | org.clojure 27 | clojure 28 | 29 | 30 | org.clojure 31 | core.async 32 | 33 | 34 | org.clojure.typed 35 | runtime.jvm 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/check/set_bang.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.check.set-bang 10 | (:require [clojure.core.typed.util-vars :as vs] 11 | [clojure.core.typed.checker.utils :as u] 12 | [clojure.core.typed.checker.check.utils :as cu] 13 | [clojure.core.typed.checker.type-rep :as r] 14 | [clojure.core.typed.checker.jvm.parse-unparse :as prs] 15 | [clojure.core.typed.errors :as err] 16 | [clojure.core.typed.checker.jvm.subtype :as sub])) 17 | 18 | (defn check-set! [check {:keys [target val env] :as expr} expected] 19 | (binding [vs/*current-expr* expr 20 | vs/*current-env* env] 21 | (let [ctarget (check target expected) 22 | cval (check val (u/expr-type ctarget))] 23 | (assoc expr 24 | u/expr-type (u/expr-type cval) 25 | :target ctarget 26 | :val cval)))) 27 | -------------------------------------------------------------------------------- /typed/lang.jvm/README.md: -------------------------------------------------------------------------------- 1 | # core.typed.lang.jvm 2 | 3 | 4 | 5 | Extensible languages in Clojure, a la Racket's #lang. 6 | 7 | ## Releases and Dependency Information 8 | 9 | Latest stable release is 1.0.1. 10 | 11 | [deps.edn](https://clojure.org/reference/deps_and_cli) JAR dependency information: 12 | 13 | ```clj 14 | org.typedclojure/core.typed.lang.jvm {:mvn/version "1.0.1"} 15 | ``` 16 | 17 | [deps.edn](https://clojure.org/reference/deps_and_cli) Git dependency information: 18 | 19 | - Note: use `clj -Sresolve` to resolve the `:tag` to a `:sha` 20 | 21 | ```clj 22 | org.clojure.typed/lang.jvm {:git/url "https://github.com/clojure/core.typed" 23 | :deps/root "typed/lang.jvm" 24 | :tag "1.0.1"} 25 | ``` 26 | 27 | [Leiningen](https://github.com/technomancy/leiningen) dependency information: 28 | 29 | ```clojure 30 | [org.typedclojure/core.typed.lang.jvm "1.0.1"] 31 | ``` 32 | 33 | [Maven](https://maven.apache.org/) dependency information: 34 | 35 | ```XML 36 | 37 | org.typedclojure 38 | core.typed.jvm 39 | 1.0.1 40 | 41 | ``` 42 | 43 | ## License 44 | 45 | Copyright © Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 46 | 47 | Licensed under the EPL (see the file epl-v10.html). 48 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/csgen_intersection.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.csgen-intersection 2 | (:require [clojure.core.typed.test.test-utils :refer :all] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.checker.cs-gen :as cgen] 5 | )) 6 | 7 | (deftest csgen-intersect 8 | (is-tc-e (do 9 | (defprotocol 10 | [[x :variance :covariant]] 11 | ICollection') 12 | (defprotocol 13 | [[x :variance :covariant]] 14 | ISeq') 15 | (defprotocol 16 | [[x :variance :covariant]] 17 | ISeqable') 18 | (defprotocol 19 | [[x :variance :covariant]] 20 | IList') 21 | (defalias 22 | NEColl' 23 | (TFn [[x :variance :covariant]] 24 | (ICollection' x))) 25 | (defalias 26 | NEASeq' 27 | (TFn [[x :variance :covariant]] 28 | (I 29 | (ICollection' x) 30 | (ISeqable' x) 31 | (ISeq' x) 32 | (IList' x) 33 | #_(CountRange 1)))) 34 | (fn [seq' :- (All [x] [(NEColl' x) -> (NEASeq' x)]) 35 | a :- (NEColl' Int)] 36 | :- (NEASeq' Number) 37 | (seq' a))))) 38 | -------------------------------------------------------------------------------- /typed/lib.clojure/README.md: -------------------------------------------------------------------------------- 1 | # core.typed.lib.clojure 2 | 3 | 4 | 5 | Type annotations and macros for the base Clojure distribution. 6 | 7 | ## Releases and Dependency Information 8 | 9 | Latest stable release is 1.0.1. 10 | 11 | [deps.edn](https://clojure.org/reference/deps_and_cli) JAR dependency information: 12 | 13 | ```clj 14 | org.clojure.typed/lib.clojure {:mvn/version "1.0.1"} 15 | ``` 16 | 17 | [deps.edn](https://clojure.org/reference/deps_and_cli) Git dependency information: 18 | 19 | - Note: use `clj -Sresolve` to resolve the `:tag` to a `:sha` 20 | 21 | ```clj 22 | org.clojure.typed/lib.clojure {:git/url "https://github.com/clojure/core.typed" 23 | :deps/root "typed/lib.clojure" 24 | :tag "1.0.1"} 25 | ``` 26 | 27 | [Leiningen](https://github.com/technomancy/leiningen) dependency information: 28 | 29 | ```clojure 30 | [org.clojure.typed/lib.clojure "1.0.1"] 31 | ``` 32 | 33 | [Maven](https://maven.apache.org/) dependency information: 34 | 35 | ```XML 36 | 37 | org.clojure 38 | core.typed.lib.clojure 39 | 1.0.1 40 | 41 | ``` 42 | 43 | ## License 44 | 45 | Copyright © Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 46 | 47 | Licensed under the EPL (see the file epl-v10.html). 48 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/array_old.clj: -------------------------------------------------------------------------------- 1 | ; some old tests that don't type check anymore but look useful 2 | (ns clojure.core.typed.test.array-old 3 | (:require [clojure.core.typed :refer [ann check-ns into-array> cf print-env ann-form] 4 | :as t] 5 | [clojure.repl :refer [pst]])) 6 | 7 | (ann my-integer-array [-> (Array Integer)]) 8 | (defn my-integer-array [] (into-array> Integer (map int [1 2]))) 9 | 10 | (ann my-int-array [-> (Array int)]) 11 | (defn my-int-array [] (into-array> int (map int [1 2]))) 12 | 13 | (ann sum [(ReadOnlyArray Number) -> Number]) 14 | (defn sum [arr] 15 | (t/loop [idx :- long 0, 16 | ret :- Number 0] 17 | (if (< idx (alength arr)) 18 | (recur 19 | (unchecked-inc idx) 20 | (+ (aget arr idx) ret)) 21 | ret))) 22 | 23 | (fn [] (sum (my-integer-array))) 24 | 25 | (ann write-integer-to-zero [(Array2 Integer t/Any) -> nil]) 26 | (defn write-integer-to-zero [arr] 27 | (aset arr 0 (int 12)) 28 | nil) 29 | 30 | (ann write-int-to-zero [(Array2 int t/Any) -> nil]) 31 | (defn write-int-to-zero [arr] 32 | (aset arr 0 (int 12)) 33 | nil) 34 | 35 | (fn [] (write-integer-to-zero my-integer-array)) 36 | (fn [] (write-int-to-zero (my-int-array))) 37 | 38 | (ann bad-modify-array [(Array Number) -> nil]) 39 | #_(defn bad-modify-array [ar] 40 | (let [ar2 (ann-form ar (Array2 Number Object))] 41 | (aset ar2 0 (new java.util.Observable)) 42 | nil)) 43 | -------------------------------------------------------------------------------- /typed/lib.core.async/deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["src"] 2 | :deps {} 3 | :mvn/repos {"sonatype-oss-public" {:url "https://oss.sonatype.org/content/groups/public/"}} 4 | :aliases {:nREPL 5 | {:extra-paths ["script"] 6 | :extra-deps 7 | {nrepl/nrepl {:mvn/version "0.4.5"} 8 | cider/piggieback {:mvn/version "0.3.8"}} 9 | :main-opts ["-m" "nrepl.cmdline" 10 | "--interactive"]} 11 | :test {:extra-deps {org.clojure/clojure {:mvn/version "1.10.1"} 12 | org.clojure/core.async {:mvn/version "1.0.567"} 13 | org.clojure.typed/runtime.jvm {:local/root "../runtime.jvm" 14 | :deps/manifest :deps} 15 | org.clojure.typed/checker.jvm {:local/root "../checker.jvm" 16 | :deps/manifest :deps} 17 | } 18 | :extra-paths ["test"]} 19 | :runner 20 | {:extra-deps 21 | {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner.git" 22 | :sha "028a6d41ac9ac5d5c405dfc38e4da6b4cc1255d5"}} 23 | :main-opts ["-m" "cognitect.test-runner" 24 | "-d" "test" 25 | "-r" ".*" 26 | ]}}} 27 | -------------------------------------------------------------------------------- /typed/lib.core.async/README.md: -------------------------------------------------------------------------------- 1 | # core.typed.lib.core.async 2 | 3 | 4 | 5 | Type annotations and macros for core.async. 6 | 7 | ## Releases and Dependency Information 8 | 9 | Latest stable release is 0.7.2. 10 | 11 | [deps.edn](https://clojure.org/reference/deps_and_cli) JAR dependency information: 12 | 13 | ```clj 14 | org.typedclojure/core.typed.lib.core.async {:mvn/version "0.7.2"} 15 | ``` 16 | 17 | [deps.edn](https://clojure.org/reference/deps_and_cli) Git dependency information: 18 | 19 | - Note: use `clj -Sresolve` to resolve the `:tag` to a `:sha` 20 | 21 | ```clj 22 | org.clojure.typed/lib.core.async {:git/url "https://github.com/clojure/core.typed" 23 | :deps/root "typed/lib.core.async" 24 | :tag "0.7.2"} 25 | ``` 26 | 27 | [Leiningen](https://github.com/technomancy/leiningen) dependency information: 28 | 29 | ```clojure 30 | [org.typedclojure/core.typed.lib.core.async "0.7.2"] 31 | ``` 32 | 33 | [Maven](https://maven.apache.org/) dependency information: 34 | 35 | ```XML 36 | 37 | org.typedclojure 38 | core.typed.lib.core.async 39 | 0.7.2 40 | 41 | ``` 42 | 43 | ## License 44 | 45 | Copyright © Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 46 | 47 | Licensed under the EPL (see the file epl-v10.html). 48 | -------------------------------------------------------------------------------- /typed/annotator.jvm/src/clojure/core/typed/annotator/debug_macros.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.annotator.debug-macros 2 | (:require [clojure.core.typed.annotator.util :refer [*debug* 3 | *debug-depth* 4 | current-time]]) 5 | ) 6 | 7 | (defmacro debug-flat 8 | ([msg] 9 | `(when (= :all *debug*) 10 | (print (str (apply str (repeat *debug-depth* " ")) *debug-depth* ": ")) 11 | ~msg))) 12 | 13 | (defmacro debug 14 | ([msg body] 15 | `(do 16 | (debug-flat ~msg) 17 | (binding [*debug-depth* (when (= :all *debug*) 18 | (inc *debug-depth*))] 19 | ~body)))) 20 | 21 | (defmacro debug-when [state msg] 22 | `(when (and (set? *debug*) 23 | (contains? *debug* ~state)) 24 | (let [msg# ~msg] 25 | (println) 26 | (println (str "SQUASH ITERATION:\n" msg#))))) 27 | 28 | (defmacro debug-squash [msg] 29 | `(debug-when :squash 30 | (str "\nSQUASH ITERATION:\n" ~msg "\n"))) 31 | 32 | (defmacro time-if-slow 33 | "Evaluates expr and prints the time it took. Returns the value of expr." 34 | [msg expr] 35 | `(let [start# (current-time) 36 | ret# ~expr 37 | msduration# (/ (double (- (current-time) start#)) 1000000.0)] 38 | (when (< 1000 msduration#) 39 | (prn (str "Elapsed time: " msduration# " msecs")) 40 | (prn ~msg)) 41 | ret#)) 42 | 43 | -------------------------------------------------------------------------------- /typed/analyzer.common/deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["src"] 2 | :deps {org.clojure/clojure {:mvn/version "1.10.1"}} 3 | :mvn/repos 4 | {"sonatype-oss-public" 5 | {:url "https://oss.sonatype.org/content/groups/public/"}}, 6 | :aliases {:nREPL 7 | {:extra-deps 8 | {nrepl/nrepl {:mvn/version "0.6.0"} 9 | cider/piggieback {:mvn/version "0.3.8"}} 10 | :main-opts ["-m" "nrepl.cmdline" 11 | "--interactive"]} 12 | :test 13 | {:extra-paths ["test"]} 14 | 15 | :test-cljs 16 | {:extra-deps {org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript.git" 17 | :sha "f97d766defd02f7d43abd37e3e9b04790a521b1e"}} 18 | :extra-paths ["test"]} 19 | 20 | :runner-cljs {:extra-deps {olical/cljs-test-runner {:mvn/version "3.7.0"}} 21 | :main-opts ["-m" "cljs-test-runner.main" 22 | "-d" "test" 23 | "--out" "target/cljs-test-runner-out"]} 24 | 25 | :runner 26 | {:extra-deps {com.cognitect/test-runner 27 | {:git/url "https://github.com/cognitect-labs/test-runner" 28 | :sha "3cb0a9daf1cb746259dc8309b218f9211ad3b33b"}} 29 | :main-opts ["-m" "cognitect.test-runner" 30 | "-r" ".*" 31 | "-d" "test"]}}} 32 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/check/multi.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.check.multi 10 | (:require [clojure.core.typed.checker.fold-rep :as fold] 11 | [clojure.core.typed.checker.type-rep :as r]) 12 | (:import (clojure.core.typed.checker.type_rep Function))) 13 | 14 | ;; Multimethod definition 15 | 16 | (def ExpectedDispatchType ::expected-dispatch-type) 17 | 18 | (fold/derive-default ExpectedDispatchType) 19 | 20 | (fold/add-fold-case ExpectedDispatchType 21 | Function 22 | (fn [ty _] 23 | (assoc ty :rng (r/make-Result r/-any)))) 24 | 25 | ;return the expected type for the dispatch fn of the given multimethod's expected type 26 | ;[Type -> Type] 27 | (defn expected-dispatch-type [mm-type] 28 | {:pre [(r/AnyType? mm-type)] 29 | :post [(r/AnyType? %)]} 30 | (fold/fold-rhs ExpectedDispatchType 31 | {:type-rec expected-dispatch-type} 32 | mm-type)) 33 | -------------------------------------------------------------------------------- /.github/workflows/clj.yml: -------------------------------------------------------------------------------- 1 | name: Run tests with clj 2 | 3 | on: 4 | push: 5 | branches: 6 | - disable-build 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | clojure: 14 | - 1.10.1 15 | #- 1.11.0-master-SNAPSHOT 16 | jdk: 17 | - 1.8 18 | #- 1.11 19 | - 1.13 20 | submodule: 21 | - typed/analyzer.common 22 | - typed/analyzer.js 23 | - typed/analyzer.jvm 24 | #- typed/checker.js 25 | - typed/checker.jvm 26 | - typed/runtime.jvm 27 | - typed/annotator.jvm 28 | - typed/lang.jvm 29 | - typed/lib.clojure 30 | - typed/lib.core.async 31 | steps: 32 | - uses: actions/checkout@v2 33 | - uses: actions/cache@v1 34 | with: 35 | path: ~/.m2/repository 36 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') } 37 | restore-keys: | 38 | ${{ runner.os }}-maven- 39 | - name: Set up JDK ${{ matrix.jdk }} 40 | uses: actions/setup-java@v1 41 | with: 42 | java-version: ${{ matrix.jdk }} 43 | - uses: DeLaGuardo/setup-clojure@2.0 44 | with: 45 | tools-deps: latest 46 | - name: Run ${{ matrix.submodule }} tests 47 | run: ./script/test -Sdeps '{:deps {org.clojure/clojure {:mvn/version "${{ matrix.clojure }}"}}}' 48 | working-directory: ${{ matrix.submodule }} 49 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/unsound_simplify.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.unsound-simplify 2 | (:require [clojure.core.typed :refer [ann ann-datatype check-ns cf] 3 | :as t]) 4 | (:import (clojure.lang Symbol))) 5 | 6 | (t/defprotocol 7 | [[a :variance :covariant]] 8 | P1 9 | (get-p1 [this] :- a)) 10 | 11 | (t/defprotocol 12 | [[a :variance :covariant]] 13 | P2 14 | (get-p2 [this] :- a)) 15 | 16 | (ann ^:no-check P1? (t/Pred (P1 t/Any))) 17 | (defn P1? [a] 18 | (satisfies? P1 a)) 19 | 20 | (ann ^:no-check P2? (t/Pred (P2 t/Any))) 21 | (defn P2? [a] 22 | (satisfies? P2 a)) 23 | 24 | (ann foo [(t/U (P1 Number) (P2 Number)) -> (t/U nil Number)]) 25 | (defn foo [p] 26 | (when (P1? p) 27 | (get-p1 p))) 28 | 29 | (ann-datatype [[a :variance :covariant]] 30 | T1 31 | [p :- a] 32 | :unchecked-ancestors [(P1 a)]) 33 | (deftype T1 [p] 34 | P1 35 | (get-p1 [this] p)) 36 | 37 | (ann-datatype [[a :variance :covariant]] 38 | T2 39 | [p :- a] 40 | :unchecked-ancestors [(P2 a)]) 41 | (deftype T2 [p] 42 | P2 43 | (get-p2 [this] p)) 44 | 45 | (ann-datatype [[a :variance :covariant]] 46 | T3 47 | [p :- a] 48 | :unchecked-ancestors [(P1 a) 49 | (P2 Symbol)]) 50 | (deftype T3 [p] 51 | P1 52 | (get-p1 [this] 'a) 53 | P2 54 | (get-p2 [this] p)) 55 | 56 | (foo (->T1 1)) 57 | (foo (->T2 2)) 58 | (foo (->T3 2)) 59 | -------------------------------------------------------------------------------- /typed/analyzer.js/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | analyzer.js 5 | A variant of tools.analyzer.js. 6 | typed.analyzer.js 7 | 1.0.2-SNAPSHOT 8 | 9 | 10 | 11 | Eclipse Public License 1.0 12 | https://opensource.org/licenses/eclipse-1.0.php 13 | repo 14 | 15 | 16 | 17 | 18 | org.clojure.typed 19 | pom 20 | 1.0.2-SNAPSHOT 21 | ../.. 22 | 23 | 24 | 25 | 26 | org.clojure 27 | clojure 28 | 29 | 30 | org.clojure.typed 31 | analyzer.common 32 | 33 | 34 | org.clojure 35 | tools.analyzer 36 | 37 | 38 | org.clojure 39 | clojurescript 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/repl_new.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.repl-new 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all])) 5 | 6 | (deftest apropos-test 7 | (is-tc-e #(apropos "clojure") [-> (Seq Sym)] 8 | :requires [[clojure.repl :refer [apropos]]]) 9 | (is-tc-e #(apropos #"") [-> (Seq Sym)] 10 | :requires [[clojure.repl :refer [apropos]]]) 11 | (is-tc-err #(apropos "clojure") [-> (Seq String)] 12 | :requires [[clojure.repl :refer [apropos]]]) 13 | (is-tc-err #(apropos 'clojure) [-> (Seq Str)] 14 | :requires [[clojure.repl :refer [apropos]]])) 15 | 16 | (deftest demunge-test 17 | (is-tc-e #(demunge "clojure.repl$demunge") [-> Str] 18 | :requires [[clojure.repl :refer [demunge]]]) 19 | (is-tc-err #(demunge "clojure.repl$demunge") [-> (Vec Any)] 20 | :requires [[clojure.repl :refer [demunge]]]) 21 | (is-tc-err #(demunge 'clojure.repl$demunge) [-> Str] 22 | :requires [[clojure.repl :refer [demunge]]])) 23 | 24 | (deftest source-fn-test 25 | (is-tc-e #(source-fn 'source) [-> (U nil Str)] 26 | :requires [[clojure.repl :refer [source-fn]]]) 27 | (is-tc-err #(source-fn 'source) [-> (Vec Any)] 28 | :requires [[clojure.repl :refer [source-fn]]]) 29 | (is-tc-err #(source-fn "source") [-> Str] 30 | :requires [[clojure.repl :refer [source-fn]]])) 31 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/tag_test.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.tag-test 2 | (:require [clojure.core.typed.test.test-utils :refer :all] 3 | [clojure.test :refer :all])) 4 | 5 | ;(deftest tag-test 6 | ; (is-tc-e (tag 1 long)) 7 | ; (is-tc-err (tag 1 Long)) 8 | ; (is-tc-e (tag 9 | ; (let [a (inc 1) 10 | ; b (* 2 10)] 11 | ; (+ a b)) 12 | ; long))) 13 | ; 14 | ;(deftest unboxed-arith-test 15 | ; (is-tc-e (do 16 | ; ;from http://stackoverflow.com/questions/11824815/fast-complex-number-arithmetic-in-clojure 17 | ; (ann-datatype complex [real :- Double 18 | ; imag :- Double]) 19 | ; (deftype complex [^double real 20 | ; ^double imag]) 21 | ; 22 | ; (ann plus [complex complex -> complex]) 23 | ; (defn plus [^complex z1 ^complex z2] 24 | ; (let [x1 (double (.real z1)) 25 | ; y1 (double (.imag z1)) 26 | ; x2 (double (.real z2)) 27 | ; y2 (double (.imag z2))] 28 | ; (tag 29 | ; (complex. (ann-form 30 | ; (tag 31 | ; (+ (tag x1 double) 32 | ; (tag x2 double)) 33 | ; double) 34 | ; Double) 35 | ; (+ y1 y2)) 36 | ; complex)))))) 37 | ; 38 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/ctyp97_tvar_scoping.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.ctyp97-tvar-scoping 2 | (:import (clojure.lang ASeq LazySeq)) 3 | (:require [clojure.core.typed :as t 4 | :refer [ann Seqable]])) 5 | 6 | (ann reduce_ (t/All [a b] 7 | (t/IFn 8 | [[a b -> b] b (Seqable a) -> b] 9 | [[a (Seqable (t/U a b)) -> (Seqable (t/U a b))] 10 | (Seqable (t/U a b)) (Seqable a) -> (Seqable (t/U a b))]))) 11 | (defn reduce_ 12 | [f zero coll] 13 | (if-let [s (seq coll)] 14 | (f (first s) 15 | (reduce_ f zero (rest s))) 16 | zero)) 17 | 18 | (ann append_ (t/All [a b] [(Seqable a) (Seqable b) -> (t/U (Seqable (t/U a b)) 19 | (ASeq (t/U a b)))])) 20 | (defn append_ 21 | [coll1 coll2] 22 | (reduce_ (t/inst cons (t/U a b)) coll2 coll1)) 23 | 24 | 25 | ; -------- main 26 | 27 | ; if you comment out this function, you will get :ok 28 | (ann map-1 (t/All [a b] [[a -> b] (Seqable a) 29 | -> (LazySeq b)])) 30 | (defn map-1 [f coll] 31 | (lazy-seq 32 | (if-let [s (seq coll)] 33 | (cons (f (first s)) 34 | (map-1 f (rest s)))))) 35 | 36 | (ann map-2 (t/All [a b] [[a -> b] (Seqable a) -> (LazySeq b)])) 37 | (defn map-2 38 | [f coll] 39 | (lazy-seq 40 | (reduce_ (t/fn [x :- a ; ERROR!! -- Cannot resolve type: a 41 | y :- (Seqable b)] 42 | (append_ [(f x)] y)) 43 | [] 44 | coll))) 45 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/dvar_env.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.dvar-env 10 | (:require [clojure.core.typed.checker.type-rep :as r] 11 | [clojure.core.typed.contract-utils :as con] 12 | [clojure.core.typed :as t]) 13 | (:import [clojure.lang Symbol] 14 | [clojure.core.typed.checker.type_rep F])) 15 | 16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 17 | ;; Dotted Variable Environment 18 | 19 | ;symbol -> F 20 | (t/ann *dotted-scope* (t/Map Symbol F)) 21 | (defonce ^:dynamic *dotted-scope* {}) 22 | (set-validator! #'*dotted-scope* (con/hash-c? symbol? r/F?)) 23 | 24 | (t/ann bound-index? [t/Any -> t/Any]) 25 | (defn bound-index? [n] 26 | (contains? *dotted-scope* n)) 27 | 28 | (defmacro with-dotted [dvars & body] 29 | `(with-dotted-mappings (into {} (for [v# ~dvars] 30 | [(:name v#) v#])) 31 | ~@body)) 32 | 33 | (defmacro with-dotted-mappings [dvar-map & body] 34 | `(binding [*dotted-scope* (merge *dotted-scope* ~dvar-map)] 35 | ~@body)) 36 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/jvm/method_override_env.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.jvm.method-override-env 10 | (:require [clojure.core.typed.env :as env] 11 | [clojure.core.typed.current-impl :as impl] 12 | [clojure.core.typed.checker.type-rep :as r])) 13 | 14 | ; Should only override a method with a more specific type 15 | ; eg. 16 | 17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 18 | ;; Method Override Env 19 | 20 | (def add-method-override impl/add-method-override) 21 | 22 | (defn reset-method-override-env! [m] 23 | (env/swap-checker! assoc impl/method-override-env-kw m) 24 | nil) 25 | 26 | (defn merge-method-override-env! [m] 27 | {:pre [(map? m)]} 28 | (env/swap-checker! update impl/method-override-env-kw merge m) 29 | nil) 30 | 31 | (defn method-override-env [] 32 | {:post [(map? %)]} 33 | (get (env/deref-checker) impl/method-override-env-kw {})) 34 | 35 | (defn get-method-override [m] 36 | {:post [((some-fn r/Poly? r/FnIntersection? nil?) %)]} 37 | (force (get (method-override-env) m))) 38 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/jvm/method_return_nilables.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.jvm.method-return-nilables 10 | (:require [clojure.core.typed.env :as env] 11 | [clojure.core.typed.current-impl :as impl])) 12 | 13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 14 | ;; Method Return non-nilables 15 | 16 | (def add-nonnilable-method-return impl/add-nonnilable-method-return) 17 | 18 | (defn reset-nonnilable-method-return-env! [m] 19 | (env/swap-checker! assoc impl/method-return-nonnilable-env-kw m) 20 | nil) 21 | 22 | (defn merge-nonnilable-method-return-env! [m] 23 | {:pre [(map? m)]} 24 | (env/swap-checker! update impl/method-return-nonnilable-env-kw merge m) 25 | nil) 26 | 27 | (defn nonnilable-method-return-env [] 28 | {:post [(map? %)]} 29 | (get (env/deref-checker) impl/method-return-nonnilable-env-kw {})) 30 | 31 | (defn nonnilable-return? [sym arity] 32 | (let [as (get (nonnilable-method-return-env) sym)] 33 | (boolean (or (= :all as) 34 | (when as 35 | (as arity)))))) 36 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/ns_options.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^:skip-wiki clojure.core.typed.checker.ns-options 10 | (:require [clojure.core.typed :as t] 11 | [clojure.core.typed.current-impl :as impl] 12 | [clojure.core.typed.env :as env])) 13 | 14 | (t/defalias NsOptions 15 | "Options for namespaces" 16 | (t/HMap :optional 17 | {:warn-on-unannotated-vars Boolean})) 18 | 19 | (t/defalias OptMap 20 | (t/Map t/Sym NsOptions)) 21 | 22 | (t/ann reset-ns-opts! [-> nil]) 23 | (defn reset-ns-opts! [] 24 | (env/swap-checker! assoc impl/ns-opts-kw {}) 25 | nil) 26 | 27 | (t/ann ^:no-check register-warn-on-unannotated-vars [t/Sym -> nil]) 28 | (def register-warn-on-unannotated-vars impl/register-warn-on-unannotated-vars) 29 | 30 | (defn get-ns-opts [nsym] 31 | {:post [(map? %)]} 32 | (get-in (env/deref-checker) [impl/ns-opts-kw nsym] {})) 33 | 34 | (t/ann ^:no-check warn-on-unannotated-vars? [t/Sym -> Boolean]) 35 | (defn warn-on-unannotated-vars? [nsym] 36 | (boolean (:warn-on-unannotated-vars (get-ns-opts nsym)))) 37 | -------------------------------------------------------------------------------- /typed/runtime.jvm/src/clojure/core/typed/hole.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns 10 | ^{:see-also [["http://matthew.brecknell.net/post/hole-driven-haskell/" "Hole Driven Development"]] 11 | :doc "This namespace contains easy tools for hole driven development"} 12 | clojure.core.typed.hole 13 | (:require [clojure.core.typed :refer [ann ann-datatype] :as t])) 14 | 15 | (ann silent-hole [-> t/Nothing]) 16 | (defn silent-hole 17 | "A silent hole. (silent-hole) passes for any other type 18 | when type checking. 19 | Use (silent-hole) as a placeholder for code. 20 | Throws an exception when evaluted." 21 | [] 22 | (throw (Exception. "silent hole"))) 23 | 24 | (ann-datatype NoisyHole []) 25 | (deftype NoisyHole []) 26 | 27 | (ann noisy-hole [-> NoisyHole]) 28 | (defn noisy-hole 29 | "A noisy hole. The type system will complain when 30 | (noisy-hole) is used in positions that expect a type 31 | more specific than Object or Any. 32 | Use (noisy-hole) as a placeholder for code. 33 | Throws an exception when evaluted." 34 | [] 35 | (throw (Exception. "noisy hole"))) 36 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/string.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.string 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all])) 5 | 6 | (deftest escape-test 7 | (is-tc-e (escape "I want 1 < 2 as HTML, & other good things." 8 | {\< "&", \> "&", \& "&"}) String 9 | :requires [[clojure.string :refer [escape]]]) 10 | (is-tc-e (escape "I want 1 < 2 as HTML, & other good things." 11 | (fn [a] 12 | (case a 13 | \< "&" 14 | \> "&" 15 | \& "&" 16 | nil))) 17 | String 18 | :requires [[clojure.string :refer [escape]]]) 19 | (is-tc-err (escape "I want 1 < 2 as HTML, & other good things." 20 | {\< "&", \> "&", \& "&"}) Boolean 21 | :requires [[clojure.string :refer [escape]]]) 22 | (is-tc-err (escape 1 {\< "&", \> "&", \& "&"}) String 23 | :requires [[clojure.string :refer [escape]]])) 24 | 25 | (deftest split-lines-test 26 | (is-tc-e (split-lines "abc\n abc") (Vec String) 27 | :requires [[clojure.string :refer [split-lines]]]) 28 | (is-tc-err (split-lines "abc\n abc") Boolean 29 | :requires [[clojure.string :refer [split-lines]]]) 30 | (is-tc-err (split-lines 1) (Vec String) 31 | :requires [[clojure.string :refer [split-lines]]])) 32 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/contrib_annotations.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.contrib-annotations 10 | (:require [clojure.core.typed :as t :refer [ann-protocol ann]])) 11 | 12 | (ann-protocol clojure.java.io/IOFactory 13 | make-reader 14 | [clojure.java.io/IOFactory '{:append t/Any, :encoding (t/U nil String)} -> java.io.BufferedReader] 15 | 16 | make-writer 17 | [clojure.java.io/IOFactory '{:append t/Any, :encoding (t/U nil String)} -> java.io.BufferedWriter] 18 | 19 | make-input-stream 20 | [clojure.java.io/IOFactory '{:append t/Any, :encoding (t/U nil String)} -> java.io.BufferedInputStream] 21 | 22 | make-output-stream 23 | [clojure.java.io/IOFactory '{:append t/Any, :encoding (t/U nil String)} -> java.io.BufferedOutputStream]) 24 | 25 | (ann ^:no-check clojure.java.io/reader 26 | [clojure.java.io/IOFactory -> java.io.BufferedReader]) 27 | (ann ^:no-check clojure.java.io/writer 28 | [clojure.java.io/IOFactory -> java.io.BufferedWriter]) 29 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/jvm/ctor_override_env.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.jvm.ctor-override-env 10 | (:require [clojure.core.typed.contract-utils :as con] 11 | [clojure.core.typed.env :as env] 12 | [clojure.core.typed.current-impl :as impl] 13 | [clojure.core.typed.checker.type-rep :as r])) 14 | 15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 16 | ;; Constructor Override Env 17 | 18 | (def add-constructor-override impl/add-constructor-override) 19 | 20 | (defn reset-constructor-override-env! [m] 21 | (env/swap-checker! assoc impl/constructor-override-env-kw m) 22 | nil) 23 | 24 | (defn merge-constructor-override-env! [m] 25 | {:pre [(map? m)]} 26 | (env/swap-checker! update impl/constructor-override-env-kw merge m) 27 | nil) 28 | 29 | (defn constructor-override-env [] 30 | {:post [(map? %)]} 31 | (get (env/deref-checker) impl/constructor-override-env-kw {})) 32 | 33 | (defn get-constructor-override [sym] 34 | {:post [((some-fn nil? r/Type?) %)]} 35 | (force (get (constructor-override-env) sym))) 36 | -------------------------------------------------------------------------------- /typed/checker.jvm/test/clojure/core/typed/test/stacktrace.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.core.typed.test.stacktrace 2 | (:require [clojure.core.typed :as t] 3 | [clojure.test :refer :all] 4 | [clojure.core.typed.test.test-utils :refer :all])) 5 | 6 | (deftest e-test 7 | (is-tc-e #(e) [-> Any] 8 | :requires [[clojure.stacktrace :refer [e]]])) 9 | 10 | (deftest print-cause-trace-test 11 | (is-tc-e #(print-cause-trace (Exception. "a")) [-> Any] 12 | :requires [[clojure.stacktrace :refer [print-cause-trace]]]) 13 | (is-tc-err #(print-cause-trace "A") [-> Any] 14 | :requires [[clojure.stacktrace :refer [print-cause-trace]]])) 15 | 16 | (deftest print-stack-trace-test 17 | (is-tc-e #(print-stack-trace (Exception. "a")) [-> Any] 18 | :requires [[clojure.stacktrace :refer [print-stack-trace]]]) 19 | (is-tc-err #(print-stack-trace "AC") [-> Any] 20 | :requires [[clojure.stacktrace :refer [print-stack-trace]]])) 21 | 22 | (deftest print-throwable-test 23 | (is-tc-e #(print-throwable (Exception. "a")) [-> Any] 24 | :requires [[clojure.stacktrace :refer [print-throwable]]]) 25 | (is-tc-err #(print-throwable "A") [-> Any] 26 | :requires [[clojure.stacktrace :refer [print-throwable]]])) 27 | 28 | (deftest root-cause-test 29 | (is-tc-e #(root-cause (Exception. "a")) [-> Throwable] 30 | :requires [[clojure.stacktrace :refer [root-cause]]]) 31 | (is-tc-err #(root-cause (Exception. "a")) [-> Exception] 32 | :requires [[clojure.stacktrace :refer [root-cause]]])) 33 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/check/monitor.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.check.monitor 10 | (:require [clojure.core.typed.checker.utils :as u] 11 | [clojure.core.typed.util-vars :as vs] 12 | [clojure.core.typed.checker.type-rep :as r] 13 | [clojure.core.typed.checker.type-ctors :as c] 14 | [clojure.core.typed.checker.jvm.subtype :as sub] 15 | [clojure.core.typed.checker.check.utils :as cu] 16 | [clojure.core.typed.checker.filter-ops :as fo] 17 | [clojure.core.typed.checker.check-below :as below])) 18 | 19 | (defn check-monitor 20 | "monitor-enter and monitor-exit both take any object and return nil" 21 | [check {:keys [target] :as expr} expected] 22 | {:pre [((some-fn nil? r/TCResult?) expected)]} 23 | (binding [vs/*current-expr* expr] 24 | (assoc expr 25 | :target (check target (r/ret (c/RClass-of Object))) 26 | u/expr-type (below/maybe-check-below (r/ret r/-nil (fo/-false-filter)) 27 | expected)))) 28 | -------------------------------------------------------------------------------- /typed/checker.js/test/cljs/cljs/core/typed/test/csp.cljs: -------------------------------------------------------------------------------- 1 | ; from David Nolen's blog 2 | (ns cljs.core.typed.test.csp 3 | (:refer-clojure :exclude [map]) 4 | (:require [cljs.core.async :as async 5 | :refer [! chan put! timeout]] 6 | [clojure.string :as string] 7 | [cljs.core.typed.test.dnolen.utils.dom :refer [by-id set-html! offset]] 8 | [cljs.core.typed.test.dnolen.utils.reactive :refer [listen map]]) 9 | (:require-macros [cljs.core.async.macros :refer [go alt!]])) 10 | 11 | (def c (chan)) 12 | 13 | (defn render [q] 14 | (apply str 15 | (for [p (reverse q)] 16 | (str "
Process " p "
")))) 17 | 18 | #_(go (while true (! c 1))) 19 | #_(go (while true (! c 2))) 20 | #_(go (while true (! c 3))) 21 | 22 | (defn peekn 23 | "Returns vector of (up to) n items from the end of vector v" 24 | [v n] 25 | (if (> (count v) n) 26 | (subvec v (- (count v) n)) 27 | v)) 28 | 29 | (let [el (by-id "ex0") 30 | out (by-id "ex0-out")] 31 | (go (loop [q []] 32 | (set-html! out (render q)) 33 | (recur (-> (conj q ( % u/expr-type r/TCResult?) 19 | (vector? (:items %))]} 20 | (let [cargs (mapv check items) 21 | res-type (r/-hvec (mapv (comp r/ret-t u/expr-type) cargs) 22 | :filters (mapv (comp r/ret-f u/expr-type) cargs) 23 | :objects (mapv (comp r/ret-o u/expr-type) cargs))] 24 | (assoc expr 25 | :items cargs 26 | u/expr-type (below/maybe-check-below 27 | (r/ret res-type (fo/-true-filter)) 28 | expected)))) 29 | -------------------------------------------------------------------------------- /typed/checker.jvm/src/clojure/core/typed/checker/jvm/method_param_nilables.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors. 2 | ;; The use and distribution terms for this software are covered by the 3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ;; which can be found in the file epl-v10.html at the root of this distribution. 5 | ;; By using this software in any fashion, you are agreeing to be bound by 6 | ;; the terms of this license. 7 | ;; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.typed.checker.jvm.method-param-nilables 10 | (:require [clojure.core.typed.env :as env] 11 | [clojure.core.typed.current-impl :as impl])) 12 | 13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 14 | ;; Method Param nilables 15 | 16 | (defn reset-method-nilable-param-env! [m] 17 | (env/swap-checker! assoc impl/method-param-nilable-env-kw m) 18 | nil) 19 | 20 | (defn merge-method-nilable-param-env! [m] 21 | {:pre [(map? m)]} 22 | (env/swap-checker! update impl/method-param-nilable-env-kw merge m) 23 | nil) 24 | 25 | (def add-method-nilable-param impl/add-method-nilable-param) 26 | 27 | (defn nilable-param-env [] 28 | {:post [(map? %)]} 29 | (get (env/deref-checker) impl/method-param-nilable-env-kw {})) 30 | 31 | (defn nilable-param? [sym arity param] 32 | (boolean 33 | (when-let [nilables (get (nilable-param-env) sym)] 34 | (when-let [params (or (nilables :all) 35 | (nilables arity))] 36 | (or (#{:all} params) 37 | (params param)))))) 38 | --------------------------------------------------------------------------------