Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Java CI

on: [push]

jobs:
build:
timeout-minutes: 5
strategy:
matrix:
jdk: ['8', '11', '17', '19']
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.jdk }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.jdk }}
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn test
- name: Configure settings.xml
run: |
mkdir -p ~/.m2
echo "<settings><servers><server><id>clojars</id><username>${{ secrets.CLOJARS_USER }}-clojars</username><password>${{ secrets.CLOJARS_PASSWORD }}</password></server></servers></settings>" > ~/.m2/settings.xml
38 changes: 38 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; https://clojure.org/dev/developing_patches#_run_an_individual_test
{:paths ["test"
"target/test-classes"]
:deps
{org.clojure/clojure {:local/root "."
:deps/manifest :pom} #_{:mvn/version "RELEASE"}
org.clojure/test.check {:mvn/version "1.1.1"}
org.clojure/test.generative {:mvn/version "1.0.0"}}
:aliases
{:dbg {:classpath-overrides {org.clojure/clojure "target/classes"}
:extra-deps {criterium/criterium {:mvn/version "0.4.4"}}}
:cognitest {:extra-deps {io.github.cognitect-labs/test-runner
{:git/tag "v0.5.0" :git/sha "b3fd0d2"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test
:exec-args {:dirs ["test"]
:patterns [;; FIXME clojure.test-clojure.ns-libs has a test that is sensitive to loading order
;; FIXME clojure.test-clojure.java-interop doesn't seem to work on JDK 17 (untested on others)
;; regex ref: https://stackoverflow.com/a/2387072
"^((?!(clojure.test-clojure.ns-libs|clojure.test-clojure.java-interop)).)*$"
]}}
:test-example-script {:jvm-opts [;; from build.xml
"-Dclojure.test-clojure.exclude-namespaces=#{clojure.test-clojure.compilation.load-ns clojure.test-clojure.ns-libs-load-later}"
"-Dclojure.compiler.direct-linking=true"]
:main-opts ["-e" "(load-file,\"src/script/run_test.clj\")"]}
:test-generative-script {:jvm-opts [;; from build.xml
"-Dclojure.compiler.direct-linking=true"]
:main-opts ["-e" "(load-file,\"src/script/run_test_generative.clj\")"]}

:kaocha {:extra-deps {lambdaisland/kaocha {:mvn/version "1.60.977"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {;:watch? true
:tests [{:id :unit
:test-paths ["test"]
:ns-patterns [".*"]}]
:reporter kaocha.report/dots
;; :plugins [:kaocha.plugin/profiling :kaocha.plugin/notifier]
}}}}
10 changes: 8 additions & 2 deletions src/clj/clojure/core_deftype.clj
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,16 @@
([^Class a ^Class b]
(if (.isAssignableFrom a b) b a)))

(defn- latest-p
"Get the latest version of the protocol before use."
[protocol]
(deref (:var protocol)))

(defn find-protocol-impl [protocol x]
(if (instance? (:on-interface protocol) x)
x
(let [c (class x)
protocol (latest-p protocol)
impl #(get (:impls protocol) %)]
(or (impl c)
(and c (or (first (remove nil? (map impl (butlast (super-chain c)))))
Expand All @@ -559,13 +565,13 @@
{:added "1.2"}
[protocol atype]
(boolean (or (implements? protocol atype)
(get (:impls protocol) atype))))
(get (:impls (latest-p protocol)) atype))))

(defn extenders
"Returns a collection of the types explicitly extending protocol"
{:added "1.2"}
[protocol]
(keys (:impls protocol)))
(keys (:impls (latest-p protocol))))

(defn satisfies?
"Returns true if x satisfies the protocol"
Expand Down
27 changes: 27 additions & 0 deletions test/clojure/test_clojure/protocols.clj
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,33 @@
(reify LongsHintedProto
(longs-hinted [_] (long-array [1])))))))

;; CLJ-2094 - Eagerly evaluated protocols should refer to latest versions

(require '[clojure.spec.alpha :as s])

(defprotocol CLJ-2094
(execute [_]))

(def partial-extends-clj-2094 (partial extends? CLJ-2094))
(def partial-extenders-clj-2094 (partial extenders CLJ-2094))
(def partial-find-protocol-method-clj-204
(partial find-protocol-method CLJ-2094 :execute))
(def partial-satisfies-clj-2094 (partial satisfies? CLJ-2094))
(s/def ::clj-2094 (partial satisfies? CLJ-2094))

(defrecord Foo-2094 [])

(extend-type Foo-2094
CLJ-2094
(execute [_]))

(deftest test-satisfies-uses-latest
(is (partial-extends-clj-2094 Foo-2094))
(is (= [Foo-2094] (partial-extenders-clj-2094)))
(is (partial-find-protocol-method-clj-204 (->Foo-2094)))
(is (partial-satisfies-clj-2094 (->Foo-2094)))
(is (s/valid? ::clj-2094 (->Foo-2094))))

;; CLJ-1180 - resolve type hints in protocol methods

(import 'clojure.lang.ISeq)
Expand Down